android.net.NetworkPolicyManager Java Examples
The following examples show how to use
android.net.NetworkPolicyManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NetworkPolicyManagerShellCommand.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private int setMeteredWifiNetwork() throws RemoteException { final PrintWriter pw = getOutPrintWriter(); final String networkId = getNextArg(); if (networkId == null) { pw.println("Error: didn't specify networkId"); return -1; } final String arg = getNextArg(); if (arg == null) { pw.println("Error: didn't specify meteredOverride"); return -1; } mInterface.setWifiMeteredOverride(NetworkPolicyManager.resolveNetworkId(networkId), stringToOverride(arg)); return -1; }
Example #2
Source File: NetworkPolicyManagerShellCommand.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private int listWifiNetworks() { final PrintWriter pw = getOutPrintWriter(); final String arg = getNextArg(); final int match; if (arg == null) { match = WifiConfiguration.METERED_OVERRIDE_NONE; } else if (Boolean.parseBoolean(arg)) { match = WifiConfiguration.METERED_OVERRIDE_METERED; } else { match = WifiConfiguration.METERED_OVERRIDE_NOT_METERED; } final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks(); for (WifiConfiguration config : configs) { if (arg == null || config.meteredOverride == match) { pw.print(NetworkPolicyManager.resolveNetworkId(config)); pw.print(';'); pw.println(overrideToString(config.meteredOverride)); } } return 0; }
Example #3
Source File: NetworkManagementService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private @NonNull String getFirewallRuleName(int chain, int rule) { String ruleName; if (getFirewallType(chain) == FIREWALL_TYPE_WHITELIST) { if (rule == NetworkPolicyManager.FIREWALL_RULE_ALLOW) { ruleName = "allow"; } else { ruleName = "deny"; } } else { // Blacklist mode if (rule == NetworkPolicyManager.FIREWALL_RULE_DENY) { ruleName = "deny"; } else { ruleName = "allow"; } } return ruleName; }
Example #4
Source File: NetworkManagementService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private boolean updateFirewallUidRuleLocked(int chain, int uid, int rule) { synchronized (mRulesLock) { SparseIntArray uidFirewallRules = getUidFirewallRulesLR(chain); final int oldUidFirewallRule = uidFirewallRules.get(uid, FIREWALL_RULE_DEFAULT); if (DBG) { Slog.d(TAG, "oldRule = " + oldUidFirewallRule + ", newRule=" + rule + " for uid=" + uid + " on chain " + chain); } if (oldUidFirewallRule == rule) { if (DBG) Slog.d(TAG, "!!!!! Skipping change"); // TODO: eventually consider throwing return false; } String ruleName = getFirewallRuleName(chain, rule); String oldRuleName = getFirewallRuleName(chain, oldUidFirewallRule); if (rule == NetworkPolicyManager.FIREWALL_RULE_DEFAULT) { uidFirewallRules.delete(uid); } else { uidFirewallRules.put(uid, rule); } return !ruleName.equals(oldRuleName); } }
Example #5
Source File: MultipathPolicyTracker.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public void start() { mCM = mContext.getSystemService(ConnectivityManager.class); mNPM = mContext.getSystemService(NetworkPolicyManager.class); mStatsManager = mContext.getSystemService(NetworkStatsManager.class); registerTrackMobileCallback(); registerNetworkPolicyListener(); final Uri defaultSettingUri = Settings.Global.getUriFor(NETWORK_DEFAULT_DAILY_MULTIPATH_QUOTA_BYTES); mResolver.registerContentObserver(defaultSettingUri, false, mSettingsObserver); final IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); mContext.registerReceiverAsUser( mConfigChangeReceiver, UserHandle.ALL, intentFilter, null, mHandler); }
Example #6
Source File: SettingsBackupAgent.java From Study_Android_Demo with Apache License 2.0 | 5 votes |
private byte[] getNetworkPolicies() { NetworkPolicyManager networkPolicyManager = (NetworkPolicyManager) getSystemService(NETWORK_POLICY_SERVICE); NetworkPolicy[] policies = networkPolicyManager.getNetworkPolicies(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (policies != null && policies.length != 0) { DataOutputStream out = new DataOutputStream(baos); try { out.writeInt(NETWORK_POLICIES_BACKUP_VERSION); out.writeInt(policies.length); for (NetworkPolicy policy : policies) { if (policy != null) { byte[] marshaledPolicy = policy.getBytesForBackup(); out.writeByte(BackupUtils.NOT_NULL); out.writeInt(marshaledPolicy.length); out.write(marshaledPolicy); } else { out.writeByte(BackupUtils.NULL); } } } catch (IOException ioe) { Log.e(TAG, "Failed to convert NetworkPolicies to byte array " + ioe.getMessage()); baos.reset(); } } return baos.toByteArray(); }
Example #7
Source File: MultipathPolicyTracker.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void registerNetworkPolicyListener() { mPolicyListener = new NetworkPolicyManager.Listener() { @Override public void onMeteredIfacesChanged(String[] meteredIfaces) { // Dispatched every time opportunistic quota is recalculated. mHandler.post(() -> updateAllMultipathBudgets()); } }; mNPM.registerListener(mPolicyListener); }
Example #8
Source File: ConnectivityController.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public ConnectivityController(JobSchedulerService service) { super(service); mConnManager = mContext.getSystemService(ConnectivityManager.class); mNetPolicyManager = mContext.getSystemService(NetworkPolicyManager.class); // We're interested in all network changes; internally we match these // network changes against the active network for each UID with jobs. final NetworkRequest request = new NetworkRequest.Builder().clearCapabilities().build(); mConnManager.registerNetworkCallback(request, mNetworkCallback); mNetPolicyManager.registerListener(mNetPolicyListener); }
Example #9
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
@Override public Object createService(ContextImpl ctx) { return new NetworkPolicyManager(INetworkPolicyManager.Stub.asInterface( ServiceManager.getService(NETWORK_POLICY_SERVICE))); }
Example #10
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
@Override public Object createService(ContextImpl ctx) { return new NetworkPolicyManager(INetworkPolicyManager.Stub.asInterface( ServiceManager.getService(NETWORK_POLICY_SERVICE))); }
Example #11
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
@Override public Object createService(ContextImpl ctx) { return new NetworkPolicyManager(INetworkPolicyManager.Stub.asInterface( ServiceManager.getService(NETWORK_POLICY_SERVICE))); }
Example #12
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
@Override public Object createService(ContextImpl ctx) { return new NetworkPolicyManager(INetworkPolicyManager.Stub.asInterface( ServiceManager.getService(NETWORK_POLICY_SERVICE))); }
Example #13
Source File: NetworkPolicyLogger.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private static String getPolicyChangedLog(int uid, int oldPolicy, int newPolicy) { return "Policy for " + uid + " changed from " + NetworkPolicyManager.uidPoliciesToString(oldPolicy) + " to " + NetworkPolicyManager.uidPoliciesToString(newPolicy); }
Example #14
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
@Override public Object createService(ContextImpl ctx) { return new NetworkPolicyManager(INetworkPolicyManager.Stub.asInterface( ServiceManager.getService(NETWORK_POLICY_SERVICE))); }
Example #15
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
@Override public Object createService(ContextImpl ctx) { return new NetworkPolicyManager(INetworkPolicyManager.Stub.asInterface( ServiceManager.getService(NETWORK_POLICY_SERVICE))); }
Example #16
Source File: SystemServiceRegistry.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@Override public NetworkPolicyManager createService(ContextImpl ctx) throws ServiceNotFoundException { return new NetworkPolicyManager(ctx, INetworkPolicyManager.Stub.asInterface( ServiceManager.getServiceOrThrow(Context.NETWORK_POLICY_SERVICE))); }
Example #17
Source File: ContextImpl.java From AndroidComponentPlugin with Apache License 2.0 | 4 votes |
@Override public Object createService(ContextImpl ctx) { return new NetworkPolicyManager(INetworkPolicyManager.Stub.asInterface( ServiceManager.getService(NETWORK_POLICY_SERVICE))); }