android7.0 點選reset app preferences,後臺services關閉
現象:
後臺FMservice執行,進入settings---apps ---menu---reset app preferences 或者該應用--permissions,手動關閉許可權,後臺service自動關閉
提取的部分log
01-01 07:09:23.100 841 854 W PackageManager: Revoke runtime permission: android.permission.RECORD_AUDIO for package com.android.fmradio
01-01 07:09:23.130 841 854 I ActivityManager: Killing 3783:com.android.fmradio/u0a90 (adj 200): permissions revoked
01-01 07:09:23.130 841 854 D ActivityManager: handleAppDiedLocked: app = ProcessRecord{4850064 3783:com.android.fmradio/u0a90}, app.pid = 3783
01-01 07:09:23.130 841 854 D ActivityManager: cleanUpApplicationRecord -- 3783
01-01 07:09:23.130 841 854 W ActivityManager: Scheduling restart of crashed service com.android.fmradio/.FmService in 1000ms
從log就可以看到,是PackageManager檢測到 com.android.fmradio應用許可權發生變化,呼叫ActivityManager中的Killing,直接殺了Killing com.android.fmradio程序
PackageManagerService.java
public void revokeRuntimePermission(String packageName, String name, int userId) {
if (!sUserManager.exists(userId)) {
Log.e(TAG, "No such user:" + userId);
return;
}
Slog.w(TAG, "Revoke runtime permission: " + name + " for package " + packageName);
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS,
"revokeRuntimePermission");
enforceCrossUserPermission(Binder.getCallingUid(), userId,
true /* requireFullPermission */, true /* checkShell */,
"revokeRuntimePermission");
final int appId;
synchronized (mPackages) {
final PackageParser.Package pkg = mPackages.get(packageName);
if (pkg == null) {
throw new IllegalArgumentException("Unknown package: " + packageName);
}
final BasePermission bp = mSettings.mPermissions.get(name);
if (bp == null) {
throw new IllegalArgumentException("Unknown permission: " + name);
}
enforceDeclaredAsUsedAndRuntimeOrDevelopmentPermission(pkg, bp);
// If a permission review is required for legacy apps we represent
// their permissions as always granted runtime ones since we need
// to keep the review required permission flag per user while an
// install permission's state is shared across all users.
/// M: CTA requirement - permission control
if (Build.isPermissionReviewRequired()
&& pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M
&& bp.isRuntime()) {
return;
}
SettingBase sb = (SettingBase) pkg.mExtras;
if (sb == null) {
throw new IllegalArgumentException("Unknown package: " + packageName);
}
final PermissionsState permissionsState = sb.getPermissionsState();
final int flags = permissionsState.getPermissionFlags(name, userId);
if ((flags & PackageManager.FLAG_PERMISSION_SYSTEM_FIXED) != 0) {
throw new SecurityException("Cannot revoke system fixed permission "
+ name + " for package " + packageName);
}
if (bp.isDevelopment()) {
// Development permissions must be handled specially, since they are not
// normal runtime permissions. For now they apply to all users.
if (permissionsState.revokeInstallPermission(bp) !=
PermissionsState.PERMISSION_OPERATION_FAILURE) {
scheduleWriteSettingsLocked();
}
return;
}
if (permissionsState.revokeRuntimePermission(bp, userId) ==
PermissionsState.PERMISSION_OPERATION_FAILURE) {
return;
}
mOnPermissionChangeListeners.onPermissionsChanged(pkg.applicationInfo.uid);
// Critical, after this call app should never have the permission.
mSettings.writeRuntimePermissionsForUserLPr(userId, true);
appId = UserHandle.getAppId(pkg.applicationInfo.uid);
}
killUid
}