Loading services/core/java/com/android/server/AppOpsService.java +88 −18 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; Loading Loading @@ -1645,7 +1644,9 @@ public class AppOpsService extends IAppOpsService.Stub { int userId = UserHandle.USER_SYSTEM; String packageName; String opStr; String modeStr; int op; int mode; int packageUid; Shell(IAppOpsService iface, AppOpsService internal) { Loading Loading @@ -1681,6 +1682,59 @@ public class AppOpsService extends IAppOpsService.Stub { } } int strModeToMode(String modeStr, PrintWriter err) { switch (modeStr) { case "allow": return AppOpsManager.MODE_ALLOWED; case "deny": return AppOpsManager.MODE_ERRORED; case "ignore": return AppOpsManager.MODE_IGNORED; case "default": return AppOpsManager.MODE_DEFAULT; } try { return Integer.parseInt(modeStr); } catch (NumberFormatException e) { } err.println("Error: Mode " + modeStr + " is not valid"); return -1; } int parseUserOpMode(int defMode, PrintWriter err) throws RemoteException { userId = UserHandle.USER_CURRENT; opStr = null; modeStr = null; for (String argument; (argument = getNextArg()) != null;) { if ("--user".equals(argument)) { userId = UserHandle.parseUserArg(getNextArgRequired()); } else { if (opStr == null) { opStr = argument; } else if (modeStr == null) { modeStr = argument; break; } } } if (opStr == null) { err.println("Error: Operation not specified."); return -1; } op = strOpToOp(opStr, err); if (op < 0) { return -1; } if (modeStr != null) { if ((mode=strModeToMode(modeStr, err)) < 0) { return -1; } } else { mode = defMode; } return 0; } int parseUserPackageOp(boolean reqOp, PrintWriter err) throws RemoteException { userId = UserHandle.USER_CURRENT; packageName = null; Loading Loading @@ -1742,6 +1796,8 @@ public class AppOpsService extends IAppOpsService.Stub { pw.println(" Set the mode for a particular application and operation."); pw.println(" get [--user <USER_ID>] <PACKAGE> [<OP>]"); pw.println(" Return the mode for a particular application and optional operation."); pw.println(" query-op [--user <USER_ID>] <OP> [<MODE>]"); pw.println(" Print all packages that currently have the given op in the given mode."); pw.println(" reset [--user <USER_ID>] [<PACKAGE>]"); pw.println(" Reset the given application or all applications to default modes."); pw.println(" write-settings"); Loading Loading @@ -1775,22 +1831,8 @@ public class AppOpsService extends IAppOpsService.Stub { return -1; } final int mode; switch (modeStr) { case "allow": mode = AppOpsManager.MODE_ALLOWED; break; case "deny": mode = AppOpsManager.MODE_ERRORED; break; case "ignore": mode = AppOpsManager.MODE_IGNORED; break; case "default": mode = AppOpsManager.MODE_DEFAULT; break; default: err.println("Error: Mode " + modeStr + " is not valid,"); final int mode = shell.strModeToMode(modeStr, err); if (mode < 0) { return -1; } Loading Loading @@ -1856,6 +1898,34 @@ public class AppOpsService extends IAppOpsService.Stub { } return 0; } case "query-op": { int res = shell.parseUserOpMode(AppOpsManager.MODE_IGNORED, err); if (res < 0) { return res; } List<AppOpsManager.PackageOps> ops = shell.mInterface.getPackagesForOps( new int[] {shell.op}); if (ops == null || ops.size() <= 0) { pw.println("No operations."); return 0; } for (int i=0; i<ops.size(); i++) { final AppOpsManager.PackageOps pkg = ops.get(i); boolean hasMatch = false; final List<AppOpsManager.OpEntry> entries = ops.get(i).getOps(); for (int j=0; j<entries.size(); j++) { AppOpsManager.OpEntry ent = entries.get(j); if (ent.getOp() == shell.op && ent.getMode() == shell.mode) { hasMatch = true; break; } } if (hasMatch) { pw.println(pkg.getPackageName()); } } return 0; } case "reset": { String packageName = null; int userId = UserHandle.USER_CURRENT; Loading services/core/java/com/android/server/am/ActiveServices.java +1 −2 Original line number Diff line number Diff line Loading @@ -62,7 +62,6 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; Loading Loading @@ -1280,7 +1279,7 @@ public final class ActiveServices { // Before going further -- if this app is not allowed to run in the // background, then at this point we aren't going to let it period. final int allowed = mAm.checkAllowBackgroundLocked( sInfo.applicationInfo.uid, sInfo.packageName, callingPid); sInfo.applicationInfo.uid, sInfo.packageName, callingPid, true); if (allowed != ActivityManager.APP_START_MODE_NORMAL) { Slog.w(TAG, "Background execution not allowed: service " + service + " to " + name.flattenToShortString() Loading services/core/java/com/android/server/am/ActivityManagerService.java +4 −3 Original line number Diff line number Diff line Loading @@ -7535,14 +7535,15 @@ public final class ActivityManagerService extends ActivityManagerNative public int getAppStartMode(int uid, String packageName) { synchronized (this) { return checkAllowBackgroundLocked(uid, packageName, -1); return checkAllowBackgroundLocked(uid, packageName, -1, true); } } int checkAllowBackgroundLocked(int uid, String packageName, int callingPid) { int checkAllowBackgroundLocked(int uid, String packageName, int callingPid, boolean allowWhenForeground) { UidRecord uidRec = mActiveUids.get(uid); if (!mLenientBackgroundCheck) { if (uidRec == null if (!allowWhenForeground || uidRec == null || uidRec.curProcState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) { if (mAppOpsService.noteOperation(AppOpsManager.OP_RUN_IN_BACKGROUND, uid, packageName) != AppOpsManager.MODE_ALLOWED) { Loading services/core/java/com/android/server/am/BroadcastQueue.java +8 −9 Original line number Diff line number Diff line Loading @@ -50,7 +50,6 @@ import android.util.EventLog; import android.util.Slog; import android.util.TimeUtils; import com.android.server.DeviceIdleController; import com.android.server.LocalServices; import static com.android.server.am.ActivityManagerDebugConfig.*; Loading Loading @@ -563,7 +562,7 @@ public final class BroadcastQueue { } if (!skip) { final int allowed = mService.checkAllowBackgroundLocked(filter.receiverList.uid, filter.packageName, -1); filter.packageName, -1, true); if (allowed == ActivityManager.APP_START_MODE_DISABLED) { Slog.w(TAG, "Background execution not allowed: receiving " + r.intent Loading Loading @@ -1102,21 +1101,21 @@ public final class BroadcastQueue { if (!skip) { final int allowed = mService.checkAllowBackgroundLocked( info.activityInfo.applicationInfo.uid, info.activityInfo.packageName, -1); info.activityInfo.applicationInfo.uid, info.activityInfo.packageName, -1, false); if (allowed != ActivityManager.APP_START_MODE_NORMAL) { // We won't allow this receiver to be launched if the app has been // completely disabled from launches, or it is delayed and the broadcast // was not explicitly sent to it and this would result in a new process // for it being created. // completely disabled from launches, or it was not explicitly sent // to it and the app is in a state that should not receive it // (depending on how checkAllowBackgroundLocked has determined that). if (allowed == ActivityManager.APP_START_MODE_DISABLED) { Slog.w(TAG, "Background execution disabled: receiving " + r.intent + " to " + component.flattenToShortString()); skip = true; } if (((r.intent.getFlags()&Intent.FLAG_RECEIVER_EXCLUDE_BACKGROUND) != 0) } else if (((r.intent.getFlags()&Intent.FLAG_RECEIVER_EXCLUDE_BACKGROUND) != 0) || (r.intent.getComponent() == null && r.intent.getPackage() == null && app == null && r.intent.getPackage() == null && ((r.intent.getFlags() & Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND) == 0))) { Slog.w(TAG, "Background execution not allowed: receiving " Loading Loading
services/core/java/com/android/server/AppOpsService.java +88 −18 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ import java.io.IOException; import java.io.PrintWriter; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; Loading Loading @@ -1645,7 +1644,9 @@ public class AppOpsService extends IAppOpsService.Stub { int userId = UserHandle.USER_SYSTEM; String packageName; String opStr; String modeStr; int op; int mode; int packageUid; Shell(IAppOpsService iface, AppOpsService internal) { Loading Loading @@ -1681,6 +1682,59 @@ public class AppOpsService extends IAppOpsService.Stub { } } int strModeToMode(String modeStr, PrintWriter err) { switch (modeStr) { case "allow": return AppOpsManager.MODE_ALLOWED; case "deny": return AppOpsManager.MODE_ERRORED; case "ignore": return AppOpsManager.MODE_IGNORED; case "default": return AppOpsManager.MODE_DEFAULT; } try { return Integer.parseInt(modeStr); } catch (NumberFormatException e) { } err.println("Error: Mode " + modeStr + " is not valid"); return -1; } int parseUserOpMode(int defMode, PrintWriter err) throws RemoteException { userId = UserHandle.USER_CURRENT; opStr = null; modeStr = null; for (String argument; (argument = getNextArg()) != null;) { if ("--user".equals(argument)) { userId = UserHandle.parseUserArg(getNextArgRequired()); } else { if (opStr == null) { opStr = argument; } else if (modeStr == null) { modeStr = argument; break; } } } if (opStr == null) { err.println("Error: Operation not specified."); return -1; } op = strOpToOp(opStr, err); if (op < 0) { return -1; } if (modeStr != null) { if ((mode=strModeToMode(modeStr, err)) < 0) { return -1; } } else { mode = defMode; } return 0; } int parseUserPackageOp(boolean reqOp, PrintWriter err) throws RemoteException { userId = UserHandle.USER_CURRENT; packageName = null; Loading Loading @@ -1742,6 +1796,8 @@ public class AppOpsService extends IAppOpsService.Stub { pw.println(" Set the mode for a particular application and operation."); pw.println(" get [--user <USER_ID>] <PACKAGE> [<OP>]"); pw.println(" Return the mode for a particular application and optional operation."); pw.println(" query-op [--user <USER_ID>] <OP> [<MODE>]"); pw.println(" Print all packages that currently have the given op in the given mode."); pw.println(" reset [--user <USER_ID>] [<PACKAGE>]"); pw.println(" Reset the given application or all applications to default modes."); pw.println(" write-settings"); Loading Loading @@ -1775,22 +1831,8 @@ public class AppOpsService extends IAppOpsService.Stub { return -1; } final int mode; switch (modeStr) { case "allow": mode = AppOpsManager.MODE_ALLOWED; break; case "deny": mode = AppOpsManager.MODE_ERRORED; break; case "ignore": mode = AppOpsManager.MODE_IGNORED; break; case "default": mode = AppOpsManager.MODE_DEFAULT; break; default: err.println("Error: Mode " + modeStr + " is not valid,"); final int mode = shell.strModeToMode(modeStr, err); if (mode < 0) { return -1; } Loading Loading @@ -1856,6 +1898,34 @@ public class AppOpsService extends IAppOpsService.Stub { } return 0; } case "query-op": { int res = shell.parseUserOpMode(AppOpsManager.MODE_IGNORED, err); if (res < 0) { return res; } List<AppOpsManager.PackageOps> ops = shell.mInterface.getPackagesForOps( new int[] {shell.op}); if (ops == null || ops.size() <= 0) { pw.println("No operations."); return 0; } for (int i=0; i<ops.size(); i++) { final AppOpsManager.PackageOps pkg = ops.get(i); boolean hasMatch = false; final List<AppOpsManager.OpEntry> entries = ops.get(i).getOps(); for (int j=0; j<entries.size(); j++) { AppOpsManager.OpEntry ent = entries.get(j); if (ent.getOp() == shell.op && ent.getMode() == shell.mode) { hasMatch = true; break; } } if (hasMatch) { pw.println(pkg.getPackageName()); } } return 0; } case "reset": { String packageName = null; int userId = UserHandle.USER_CURRENT; Loading
services/core/java/com/android/server/am/ActiveServices.java +1 −2 Original line number Diff line number Diff line Loading @@ -62,7 +62,6 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; Loading Loading @@ -1280,7 +1279,7 @@ public final class ActiveServices { // Before going further -- if this app is not allowed to run in the // background, then at this point we aren't going to let it period. final int allowed = mAm.checkAllowBackgroundLocked( sInfo.applicationInfo.uid, sInfo.packageName, callingPid); sInfo.applicationInfo.uid, sInfo.packageName, callingPid, true); if (allowed != ActivityManager.APP_START_MODE_NORMAL) { Slog.w(TAG, "Background execution not allowed: service " + service + " to " + name.flattenToShortString() Loading
services/core/java/com/android/server/am/ActivityManagerService.java +4 −3 Original line number Diff line number Diff line Loading @@ -7535,14 +7535,15 @@ public final class ActivityManagerService extends ActivityManagerNative public int getAppStartMode(int uid, String packageName) { synchronized (this) { return checkAllowBackgroundLocked(uid, packageName, -1); return checkAllowBackgroundLocked(uid, packageName, -1, true); } } int checkAllowBackgroundLocked(int uid, String packageName, int callingPid) { int checkAllowBackgroundLocked(int uid, String packageName, int callingPid, boolean allowWhenForeground) { UidRecord uidRec = mActiveUids.get(uid); if (!mLenientBackgroundCheck) { if (uidRec == null if (!allowWhenForeground || uidRec == null || uidRec.curProcState >= ActivityManager.PROCESS_STATE_IMPORTANT_BACKGROUND) { if (mAppOpsService.noteOperation(AppOpsManager.OP_RUN_IN_BACKGROUND, uid, packageName) != AppOpsManager.MODE_ALLOWED) { Loading
services/core/java/com/android/server/am/BroadcastQueue.java +8 −9 Original line number Diff line number Diff line Loading @@ -50,7 +50,6 @@ import android.util.EventLog; import android.util.Slog; import android.util.TimeUtils; import com.android.server.DeviceIdleController; import com.android.server.LocalServices; import static com.android.server.am.ActivityManagerDebugConfig.*; Loading Loading @@ -563,7 +562,7 @@ public final class BroadcastQueue { } if (!skip) { final int allowed = mService.checkAllowBackgroundLocked(filter.receiverList.uid, filter.packageName, -1); filter.packageName, -1, true); if (allowed == ActivityManager.APP_START_MODE_DISABLED) { Slog.w(TAG, "Background execution not allowed: receiving " + r.intent Loading Loading @@ -1102,21 +1101,21 @@ public final class BroadcastQueue { if (!skip) { final int allowed = mService.checkAllowBackgroundLocked( info.activityInfo.applicationInfo.uid, info.activityInfo.packageName, -1); info.activityInfo.applicationInfo.uid, info.activityInfo.packageName, -1, false); if (allowed != ActivityManager.APP_START_MODE_NORMAL) { // We won't allow this receiver to be launched if the app has been // completely disabled from launches, or it is delayed and the broadcast // was not explicitly sent to it and this would result in a new process // for it being created. // completely disabled from launches, or it was not explicitly sent // to it and the app is in a state that should not receive it // (depending on how checkAllowBackgroundLocked has determined that). if (allowed == ActivityManager.APP_START_MODE_DISABLED) { Slog.w(TAG, "Background execution disabled: receiving " + r.intent + " to " + component.flattenToShortString()); skip = true; } if (((r.intent.getFlags()&Intent.FLAG_RECEIVER_EXCLUDE_BACKGROUND) != 0) } else if (((r.intent.getFlags()&Intent.FLAG_RECEIVER_EXCLUDE_BACKGROUND) != 0) || (r.intent.getComponent() == null && r.intent.getPackage() == null && app == null && r.intent.getPackage() == null && ((r.intent.getFlags() & Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND) == 0))) { Slog.w(TAG, "Background execution not allowed: receiving " Loading