diff options
17 files changed, 827 insertions, 558 deletions
@@ -156,6 +156,8 @@ LOCAL_SRC_FILES += \ core/java/android/hardware/display/IDisplayManager.aidl \ core/java/android/hardware/display/IDisplayManagerCallback.aidl \ core/java/android/hardware/display/IVirtualDisplayCallback.aidl \ + core/java/android/hardware/fingerprint/IFingerprintDaemon.aidl \ + core/java/android/hardware/fingerprint/IFingerprintDaemonCallback.aidl \ core/java/android/hardware/fingerprint/IFingerprintService.aidl \ core/java/android/hardware/fingerprint/IFingerprintServiceReceiver.aidl \ core/java/android/hardware/hdmi/IHdmiControlCallback.aidl \ diff --git a/core/java/android/hardware/fingerprint/FingerprintManager.java b/core/java/android/hardware/fingerprint/FingerprintManager.java index 338bd76..caf21d5 100644 --- a/core/java/android/hardware/fingerprint/FingerprintManager.java +++ b/core/java/android/hardware/fingerprint/FingerprintManager.java @@ -729,12 +729,6 @@ public class FingerprintManager { } } - private void clearCallbacks() { - mAuthenticationCallback = null; - mEnrollmentCallback = null; - mRemovalCallback = null; - } - private void cancelEnrollment() { if (mService != null) try { mService.cancelEnrollment(mToken); diff --git a/core/java/android/hardware/fingerprint/IFingerprintDaemon.aidl b/core/java/android/hardware/fingerprint/IFingerprintDaemon.aidl new file mode 100644 index 0000000..186d36e --- /dev/null +++ b/core/java/android/hardware/fingerprint/IFingerprintDaemon.aidl @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.hardware.fingerprint; + +import android.hardware.fingerprint.IFingerprintDaemonCallback; + +/** + * Communication channel from FingerprintService to FingerprintDaemon (fingerprintd) + * @hide + */ + +interface IFingerprintDaemon { + int authenticate(long sessionId, int groupId); + int cancelAuthentication(); + int enroll(in byte [] token, int groupId, int timeout); + int cancelEnrollment(); + long preEnroll(); + int remove(int fingerId, int groupId); + long getAuthenticatorId(); + int setActiveGroup(int groupId, in byte[] path); + long openHal(); + int closeHal(); + void init(IFingerprintDaemonCallback callback); +} diff --git a/core/java/android/hardware/fingerprint/IFingerprintDaemonCallback.aidl b/core/java/android/hardware/fingerprint/IFingerprintDaemonCallback.aidl new file mode 100644 index 0000000..bd8ad6e --- /dev/null +++ b/core/java/android/hardware/fingerprint/IFingerprintDaemonCallback.aidl @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package android.hardware.fingerprint; + +/** + * Communication channel from the fingerprintd back to FingerprintService. + * @hide + */ + interface IFingerprintDaemonCallback { + void onEnrollResult(long deviceId, int fingerId, int groupId, int remaining); + void onAcquired(long deviceId, int acquiredInfo); + void onAuthenticated(long deviceId, int fingerId, int groupId); + void onError(long deviceId, int error); + void onRemoved(long deviceId, int fingerId, int groupId); + void onEnumerate(long deviceId, in int [] fingerIds, in int [] groupIds); +} diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java index 5fece8d..5360645 100644 --- a/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/Keyguard/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -361,9 +361,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { Log.d(TAG, "Fingerprint disabled by DPM for userId: " + userId); return; } - if (groupId == userId) { - onFingerprintAuthenticated(groupId); - } + onFingerprintAuthenticated(userId); } finally { setFingerprintRunningDetectionRunning(false); } diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java index ad710a6..1dba942 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java @@ -201,14 +201,14 @@ public class SettingsProvider extends ContentProvider { @GuardedBy("mLock") private SettingsRegistry mSettingsRegistry; - @GuardedBy("mLock") - private UserManager mUserManager; + // We have to call in the user manager with no lock held, + private volatile UserManager mUserManager; - @GuardedBy("mLock") - private AppOpsManager mAppOpsManager; + // We have to call in the app ops manager with no lock held, + private volatile AppOpsManager mAppOpsManager; - @GuardedBy("mLock") - private PackageManager mPackageManager; + // We have to call in the package manager with no lock held, + private volatile PackageManager mPackageManager; @Override public boolean onCreate() { @@ -224,44 +224,46 @@ public class SettingsProvider extends ContentProvider { @Override public Bundle call(String method, String name, Bundle args) { - synchronized (mLock) { - final int requestingUserId = getRequestingUserId(args); - switch (method) { - case Settings.CALL_METHOD_GET_GLOBAL: { - Setting setting = getGlobalSettingLocked(name); - return packageValueForCallResult(setting); - } - - case Settings.CALL_METHOD_GET_SECURE: { - Setting setting = getSecureSettingLocked(name, requestingUserId); - return packageValueForCallResult(setting); - } + final int requestingUserId = getRequestingUserId(args); + switch (method) { + case Settings.CALL_METHOD_GET_GLOBAL: { + Setting setting = getGlobalSetting(name); + return packageValueForCallResult(setting); + } - case Settings.CALL_METHOD_GET_SYSTEM: { - Setting setting = getSystemSettingLocked(name, requestingUserId); - return packageValueForCallResult(setting); - } + case Settings.CALL_METHOD_GET_SECURE: { + Setting setting = getSecureSetting(name, requestingUserId); + return packageValueForCallResult(setting); + } - case Settings.CALL_METHOD_PUT_GLOBAL: { - String value = getSettingValue(args); - insertGlobalSettingLocked(name, value, requestingUserId); - } break; + case Settings.CALL_METHOD_GET_SYSTEM: { + Setting setting = getSystemSetting(name, requestingUserId); + return packageValueForCallResult(setting); + } - case Settings.CALL_METHOD_PUT_SECURE: { - String value = getSettingValue(args); - insertSecureSettingLocked(name, value, requestingUserId); - } break; + case Settings.CALL_METHOD_PUT_GLOBAL: { + String value = getSettingValue(args); + insertGlobalSetting(name, value, requestingUserId); + break; + } - case Settings.CALL_METHOD_PUT_SYSTEM: { - String value = getSettingValue(args); - insertSystemSettingLocked(name, value, requestingUserId); - } break; + case Settings.CALL_METHOD_PUT_SECURE: { + String value = getSettingValue(args); + insertSecureSetting(name, value, requestingUserId); + break; + } - default: { - Slog.w(LOG_TAG, "call() with invalid method: " + method); - } break; + case Settings.CALL_METHOD_PUT_SYSTEM: { + String value = getSettingValue(args); + insertSystemSetting(name, value, requestingUserId); + break; } + + default: { + Slog.w(LOG_TAG, "call() with invalid method: " + method); + } break; } + return null; } @@ -271,7 +273,7 @@ public class SettingsProvider extends ContentProvider { if (TextUtils.isEmpty(args.name)) { return "vnd.android.cursor.dir/" + args.table; } else { - return "vnd.android.cursor.item/" + args.table; + return "vnd.android.cursor.item/" + args.table; } } @@ -290,40 +292,38 @@ public class SettingsProvider extends ContentProvider { return new MatrixCursor(normalizedProjection, 0); } - synchronized (mLock) { - switch (args.table) { - case TABLE_GLOBAL: { - if (args.name != null) { - Setting setting = getGlobalSettingLocked(args.name); - return packageSettingForQuery(setting, normalizedProjection); - } else { - return getAllGlobalSettingsLocked(projection); - } + switch (args.table) { + case TABLE_GLOBAL: { + if (args.name != null) { + Setting setting = getGlobalSetting(args.name); + return packageSettingForQuery(setting, normalizedProjection); + } else { + return getAllGlobalSettings(projection); } + } - case TABLE_SECURE: { - final int userId = UserHandle.getCallingUserId(); - if (args.name != null) { - Setting setting = getSecureSettingLocked(args.name, userId); - return packageSettingForQuery(setting, normalizedProjection); - } else { - return getAllSecureSettingsLocked(userId, projection); - } + case TABLE_SECURE: { + final int userId = UserHandle.getCallingUserId(); + if (args.name != null) { + Setting setting = getSecureSetting(args.name, userId); + return packageSettingForQuery(setting, normalizedProjection); + } else { + return getAllSecureSettings(userId, projection); } + } - case TABLE_SYSTEM: { - final int userId = UserHandle.getCallingUserId(); - if (args.name != null) { - Setting setting = getSystemSettingLocked(args.name, userId); - return packageSettingForQuery(setting, normalizedProjection); - } else { - return getAllSystemSettingsLocked(userId, projection); - } + case TABLE_SYSTEM: { + final int userId = UserHandle.getCallingUserId(); + if (args.name != null) { + Setting setting = getSystemSetting(args.name, userId); + return packageSettingForQuery(setting, normalizedProjection); + } else { + return getAllSystemSettings(userId, projection); } + } - default: { - throw new IllegalArgumentException("Invalid Uri path:" + uri); - } + default: { + throw new IllegalArgumentException("Invalid Uri path:" + uri); } } } @@ -348,29 +348,27 @@ public class SettingsProvider extends ContentProvider { String value = values.getAsString(Settings.Secure.VALUE); - synchronized (mLock) { - switch (table) { - case TABLE_GLOBAL: { - if (insertGlobalSettingLocked(name, value, UserHandle.getCallingUserId())) { - return Uri.withAppendedPath(Settings.Global.CONTENT_URI, name); - } - } break; - - case TABLE_SECURE: { - if (insertSecureSettingLocked(name, value, UserHandle.getCallingUserId())) { - return Uri.withAppendedPath(Settings.Secure.CONTENT_URI, name); - } - } break; + switch (table) { + case TABLE_GLOBAL: { + if (insertGlobalSetting(name, value, UserHandle.getCallingUserId())) { + return Uri.withAppendedPath(Settings.Global.CONTENT_URI, name); + } + } break; - case TABLE_SYSTEM: { - if (insertSystemSettingLocked(name, value, UserHandle.getCallingUserId())) { - return Uri.withAppendedPath(Settings.System.CONTENT_URI, name); - } - } break; + case TABLE_SECURE: { + if (insertSecureSetting(name, value, UserHandle.getCallingUserId())) { + return Uri.withAppendedPath(Settings.Secure.CONTENT_URI, name); + } + } break; - default: { - throw new IllegalArgumentException("Bad Uri path:" + uri); + case TABLE_SYSTEM: { + if (insertSystemSetting(name, value, UserHandle.getCallingUserId())) { + return Uri.withAppendedPath(Settings.System.CONTENT_URI, name); } + } break; + + default: { + throw new IllegalArgumentException("Bad Uri path:" + uri); } } @@ -412,26 +410,25 @@ public class SettingsProvider extends ContentProvider { return 0; } - synchronized (mLock) { - switch (args.table) { - case TABLE_GLOBAL: { - final int userId = UserHandle.getCallingUserId(); - return deleteGlobalSettingLocked(args.name, userId) ? 1 : 0; - } - case TABLE_SECURE: { - final int userId = UserHandle.getCallingUserId(); - return deleteSecureSettingLocked(args.name, userId) ? 1 : 0; - } + switch (args.table) { + case TABLE_GLOBAL: { + final int userId = UserHandle.getCallingUserId(); + return deleteGlobalSetting(args.name, userId) ? 1 : 0; + } - case TABLE_SYSTEM: { - final int userId = UserHandle.getCallingUserId(); - return deleteSystemSettingLocked(args.name, userId) ? 1 : 0; - } + case TABLE_SECURE: { + final int userId = UserHandle.getCallingUserId(); + return deleteSecureSetting(args.name, userId) ? 1 : 0; + } - default: { - throw new IllegalArgumentException("Bad Uri path:" + uri); - } + case TABLE_SYSTEM: { + final int userId = UserHandle.getCallingUserId(); + return deleteSystemSetting(args.name, userId) ? 1 : 0; + } + + default: { + throw new IllegalArgumentException("Bad Uri path:" + uri); } } } @@ -454,26 +451,24 @@ public class SettingsProvider extends ContentProvider { return 0; } - synchronized (mLock) { - switch (args.table) { - case TABLE_GLOBAL: { - final int userId = UserHandle.getCallingUserId(); - return updateGlobalSettingLocked(args.name, value, userId) ? 1 : 0; - } + switch (args.table) { + case TABLE_GLOBAL: { + final int userId = UserHandle.getCallingUserId(); + return updateGlobalSetting(args.name, value, userId) ? 1 : 0; + } - case TABLE_SECURE: { - final int userId = UserHandle.getCallingUserId(); - return updateSecureSettingLocked(args.name, value, userId) ? 1 : 0; - } + case TABLE_SECURE: { + final int userId = UserHandle.getCallingUserId(); + return updateSecureSetting(args.name, value, userId) ? 1 : 0; + } - case TABLE_SYSTEM: { - final int userId = UserHandle.getCallingUserId(); - return updateSystemSettingLocked(args.name, value, userId) ? 1 : 0; - } + case TABLE_SYSTEM: { + final int userId = UserHandle.getCallingUserId(); + return updateSystemSetting(args.name, value, userId) ? 1 : 0; + } - default: { - throw new IllegalArgumentException("Invalid Uri path:" + uri); - } + default: { + throw new IllegalArgumentException("Invalid Uri path:" + uri); } } } @@ -504,18 +499,18 @@ public class SettingsProvider extends ContentProvider { private void dumpForUser(int userId, PrintWriter pw) { if (userId == UserHandle.USER_OWNER) { pw.println("GLOBAL SETTINGS (user " + userId + ")"); - Cursor globalCursor = getAllGlobalSettingsLocked(ALL_COLUMNS); + Cursor globalCursor = getAllGlobalSettings(ALL_COLUMNS); dumpSettings(globalCursor, pw); pw.println(); } pw.println("SECURE SETTINGS (user " + userId + ")"); - Cursor secureCursor = getAllSecureSettingsLocked(userId, ALL_COLUMNS); + Cursor secureCursor = getAllSecureSettings(userId, ALL_COLUMNS); dumpSettings(secureCursor, pw); pw.println(); pw.println("SYSTEM SETTINGS (user " + userId + ")"); - Cursor systemCursor = getAllSystemSettingsLocked(userId, ALL_COLUMNS); + Cursor systemCursor = getAllSystemSettings(userId, ALL_COLUMNS); dumpSettings(systemCursor, pw); pw.println(); } @@ -575,64 +570,68 @@ public class SettingsProvider extends ContentProvider { UserHandle.ALL, true); } - private Cursor getAllGlobalSettingsLocked(String[] projection) { + private Cursor getAllGlobalSettings(String[] projection) { if (DEBUG) { - Slog.v(LOG_TAG, "getAllGlobalSettingsLocked()"); + Slog.v(LOG_TAG, "getAllGlobalSettings()"); } - // Get the settings. - SettingsState settingsState = mSettingsRegistry.getSettingsLocked( - SettingsRegistry.SETTINGS_TYPE_GLOBAL, UserHandle.USER_OWNER); + synchronized (mLock) { + // Get the settings. + SettingsState settingsState = mSettingsRegistry.getSettingsLocked( + SettingsRegistry.SETTINGS_TYPE_GLOBAL, UserHandle.USER_OWNER); - List<String> names = settingsState.getSettingNamesLocked(); + List<String> names = settingsState.getSettingNamesLocked(); - final int nameCount = names.size(); + final int nameCount = names.size(); - String[] normalizedProjection = normalizeProjection(projection); - MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount); + String[] normalizedProjection = normalizeProjection(projection); + MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount); - // Anyone can get the global settings, so no security checks. - for (int i = 0; i < nameCount; i++) { - String name = names.get(i); - Setting setting = settingsState.getSettingLocked(name); - appendSettingToCursor(result, setting); - } + // Anyone can get the global settings, so no security checks. + for (int i = 0; i < nameCount; i++) { + String name = names.get(i); + Setting setting = settingsState.getSettingLocked(name); + appendSettingToCursor(result, setting); + } - return result; + return result; + } } - private Setting getGlobalSettingLocked(String name) { + private Setting getGlobalSetting(String name) { if (DEBUG) { Slog.v(LOG_TAG, "getGlobalSetting(" + name + ")"); } // Get the value. - return mSettingsRegistry.getSettingLocked(SettingsRegistry.SETTINGS_TYPE_GLOBAL, - UserHandle.USER_OWNER, name); + synchronized (mLock) { + return mSettingsRegistry.getSettingLocked(SettingsRegistry.SETTINGS_TYPE_GLOBAL, + UserHandle.USER_OWNER, name); + } } - private boolean updateGlobalSettingLocked(String name, String value, int requestingUserId) { + private boolean updateGlobalSetting(String name, String value, int requestingUserId) { if (DEBUG) { - Slog.v(LOG_TAG, "updateGlobalSettingLocked(" + name + ", " + value + ")"); + Slog.v(LOG_TAG, "updateGlobalSetting(" + name + ", " + value + ")"); } - return mutateGlobalSettingLocked(name, value, requestingUserId, MUTATION_OPERATION_UPDATE); + return mutateGlobalSetting(name, value, requestingUserId, MUTATION_OPERATION_UPDATE); } - private boolean insertGlobalSettingLocked(String name, String value, int requestingUserId) { + private boolean insertGlobalSetting(String name, String value, int requestingUserId) { if (DEBUG) { - Slog.v(LOG_TAG, "insertGlobalSettingLocked(" + name + ", " + value + ")"); + Slog.v(LOG_TAG, "insertGlobalSetting(" + name + ", " + value + ")"); } - return mutateGlobalSettingLocked(name, value, requestingUserId, MUTATION_OPERATION_INSERT); + return mutateGlobalSetting(name, value, requestingUserId, MUTATION_OPERATION_INSERT); } - private boolean deleteGlobalSettingLocked(String name, int requestingUserId) { + private boolean deleteGlobalSetting(String name, int requestingUserId) { if (DEBUG) { Slog.v(LOG_TAG, "deleteGlobalSettingLocked(" + name + ")"); } - return mutateGlobalSettingLocked(name, null, requestingUserId, MUTATION_OPERATION_DELETE); + return mutateGlobalSetting(name, null, requestingUserId, MUTATION_OPERATION_DELETE); } - private boolean mutateGlobalSettingLocked(String name, String value, int requestingUserId, + private boolean mutateGlobalSetting(String name, String value, int requestingUserId, int operation) { // Make sure the caller can change the settings - treated as secure. enforceWritePermission(Manifest.permission.WRITE_SECURE_SETTINGS); @@ -651,28 +650,32 @@ public class SettingsProvider extends ContentProvider { } // Perform the mutation. - switch (operation) { - case MUTATION_OPERATION_INSERT: { - return mSettingsRegistry.insertSettingLocked(SettingsRegistry.SETTINGS_TYPE_GLOBAL, - UserHandle.USER_OWNER, name, value, getCallingPackage()); - } + synchronized (mLock) { + switch (operation) { + case MUTATION_OPERATION_INSERT: { + return mSettingsRegistry + .insertSettingLocked(SettingsRegistry.SETTINGS_TYPE_GLOBAL, + UserHandle.USER_OWNER, name, value, getCallingPackage()); + } - case MUTATION_OPERATION_DELETE: { - return mSettingsRegistry.deleteSettingLocked( - SettingsRegistry.SETTINGS_TYPE_GLOBAL, - UserHandle.USER_OWNER, name); - } + case MUTATION_OPERATION_DELETE: { + return mSettingsRegistry.deleteSettingLocked( + SettingsRegistry.SETTINGS_TYPE_GLOBAL, + UserHandle.USER_OWNER, name); + } - case MUTATION_OPERATION_UPDATE: { - return mSettingsRegistry.updateSettingLocked(SettingsRegistry.SETTINGS_TYPE_GLOBAL, - UserHandle.USER_OWNER, name, value, getCallingPackage()); + case MUTATION_OPERATION_UPDATE: { + return mSettingsRegistry + .updateSettingLocked(SettingsRegistry.SETTINGS_TYPE_GLOBAL, + UserHandle.USER_OWNER, name, value, getCallingPackage()); + } } } return false; } - private Cursor getAllSecureSettingsLocked(int userId, String[] projection) { + private Cursor getAllSecureSettings(int userId, String[] projection) { if (DEBUG) { Slog.v(LOG_TAG, "getAllSecureSettings(" + userId + ")"); } @@ -680,34 +683,36 @@ public class SettingsProvider extends ContentProvider { // Resolve the userId on whose behalf the call is made. final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId); - List<String> names = mSettingsRegistry.getSettingsNamesLocked( - SettingsRegistry.SETTINGS_TYPE_SECURE, callingUserId); + synchronized (mLock) { + List<String> names = mSettingsRegistry.getSettingsNamesLocked( + SettingsRegistry.SETTINGS_TYPE_SECURE, callingUserId); - final int nameCount = names.size(); + final int nameCount = names.size(); - String[] normalizedProjection = normalizeProjection(projection); - MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount); + String[] normalizedProjection = normalizeProjection(projection); + MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount); - for (int i = 0; i < nameCount; i++) { - String name = names.get(i); + for (int i = 0; i < nameCount; i++) { + String name = names.get(i); + // Determine the owning user as some profile settings are cloned from the parent. + final int owningUserId = resolveOwningUserIdForSecureSettingLocked(callingUserId, + name); - // Determine the owning user as some profile settings are cloned from the parent. - final int owningUserId = resolveOwningUserIdForSecureSettingLocked(callingUserId, name); + // Special case for location (sigh). + if (isLocationProvidersAllowedRestricted(name, callingUserId, owningUserId)) { + return null; + } - // Special case for location (sigh). - if (isLocationProvidersAllowedRestricted(name, callingUserId, owningUserId)) { - return null; + Setting setting = mSettingsRegistry.getSettingLocked( + SettingsRegistry.SETTINGS_TYPE_SECURE, owningUserId, name); + appendSettingToCursor(result, setting); } - Setting setting = mSettingsRegistry.getSettingLocked( - SettingsRegistry.SETTINGS_TYPE_SECURE, owningUserId, name); - appendSettingToCursor(result, setting); + return result; } - - return result; } - private Setting getSecureSettingLocked(String name, int requestingUserId) { + private Setting getSecureSetting(String name, int requestingUserId) { if (DEBUG) { Slog.v(LOG_TAG, "getSecureSetting(" + name + ", " + requestingUserId + ")"); } @@ -724,37 +729,39 @@ public class SettingsProvider extends ContentProvider { } // Get the value. - return mSettingsRegistry.getSettingLocked(SettingsRegistry.SETTINGS_TYPE_SECURE, - owningUserId, name); + synchronized (mLock) { + return mSettingsRegistry.getSettingLocked(SettingsRegistry.SETTINGS_TYPE_SECURE, + owningUserId, name); + } } - private boolean insertSecureSettingLocked(String name, String value, int requestingUserId) { + private boolean insertSecureSetting(String name, String value, int requestingUserId) { if (DEBUG) { - Slog.v(LOG_TAG, "insertSecureSettingLocked(" + name + ", " + value + ", " + Slog.v(LOG_TAG, "insertSecureSetting(" + name + ", " + value + ", " + requestingUserId + ")"); } - return mutateSecureSettingLocked(name, value, requestingUserId, MUTATION_OPERATION_INSERT); + return mutateSecureSetting(name, value, requestingUserId, MUTATION_OPERATION_INSERT); } - private boolean deleteSecureSettingLocked(String name, int requestingUserId) { + private boolean deleteSecureSetting(String name, int requestingUserId) { if (DEBUG) { - Slog.v(LOG_TAG, "deleteSecureSettingLocked(" + name + ", " + requestingUserId + ")"); + Slog.v(LOG_TAG, "deleteSecureSetting(" + name + ", " + requestingUserId + ")"); } - return mutateSecureSettingLocked(name, null, requestingUserId, MUTATION_OPERATION_DELETE); + return mutateSecureSetting(name, null, requestingUserId, MUTATION_OPERATION_DELETE); } - private boolean updateSecureSettingLocked(String name, String value, int requestingUserId) { + private boolean updateSecureSetting(String name, String value, int requestingUserId) { if (DEBUG) { - Slog.v(LOG_TAG, "updateSecureSettingLocked(" + name + ", " + value + ", " + Slog.v(LOG_TAG, "updateSecureSetting(" + name + ", " + value + ", " + requestingUserId + ")"); } - return mutateSecureSettingLocked(name, value, requestingUserId, MUTATION_OPERATION_UPDATE); + return mutateSecureSetting(name, value, requestingUserId, MUTATION_OPERATION_UPDATE); } - private boolean mutateSecureSettingLocked(String name, String value, int requestingUserId, + private boolean mutateSecureSetting(String name, String value, int requestingUserId, int operation) { // Make sure the caller can change the settings. enforceWritePermission(Manifest.permission.WRITE_SECURE_SETTINGS); @@ -786,58 +793,65 @@ public class SettingsProvider extends ContentProvider { } // Mutate the value. - switch(operation) { - case MUTATION_OPERATION_INSERT: { - return mSettingsRegistry.insertSettingLocked(SettingsRegistry.SETTINGS_TYPE_SECURE, - owningUserId, name, value, getCallingPackage()); - } + synchronized (mLock) { + switch (operation) { + case MUTATION_OPERATION_INSERT: { + return mSettingsRegistry + .insertSettingLocked(SettingsRegistry.SETTINGS_TYPE_SECURE, + owningUserId, name, value, getCallingPackage()); + } - case MUTATION_OPERATION_DELETE: { - return mSettingsRegistry.deleteSettingLocked( - SettingsRegistry.SETTINGS_TYPE_SECURE, - owningUserId, name); - } + case MUTATION_OPERATION_DELETE: { + return mSettingsRegistry.deleteSettingLocked( + SettingsRegistry.SETTINGS_TYPE_SECURE, + owningUserId, name); + } - case MUTATION_OPERATION_UPDATE: { - return mSettingsRegistry.updateSettingLocked(SettingsRegistry.SETTINGS_TYPE_SECURE, - owningUserId, name, value, getCallingPackage()); + case MUTATION_OPERATION_UPDATE: { + return mSettingsRegistry + .updateSettingLocked(SettingsRegistry.SETTINGS_TYPE_SECURE, + owningUserId, name, value, getCallingPackage()); + } } } return false; } - private Cursor getAllSystemSettingsLocked(int userId, String[] projection) { + private Cursor getAllSystemSettings(int userId, String[] projection) { if (DEBUG) { - Slog.v(LOG_TAG, "getAllSecureSystemLocked(" + userId + ")"); + Slog.v(LOG_TAG, "getAllSecureSystem(" + userId + ")"); } // Resolve the userId on whose behalf the call is made. final int callingUserId = resolveCallingUserIdEnforcingPermissionsLocked(userId); - List<String> names = mSettingsRegistry.getSettingsNamesLocked( - SettingsRegistry.SETTINGS_TYPE_SYSTEM, callingUserId); + synchronized (mLock) { + List<String> names = mSettingsRegistry.getSettingsNamesLocked( + SettingsRegistry.SETTINGS_TYPE_SYSTEM, callingUserId); - final int nameCount = names.size(); + final int nameCount = names.size(); - String[] normalizedProjection = normalizeProjection(projection); - MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount); + String[] normalizedProjection = normalizeProjection(projection); + MatrixCursor result = new MatrixCursor(normalizedProjection, nameCount); - for (int i = 0; i < nameCount; i++) { - String name = names.get(i); + for (int i = 0; i < nameCount; i++) { + String name = names.get(i); - // Determine the owning user as some profile settings are cloned from the parent. - final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId, name); + // Determine the owning user as some profile settings are cloned from the parent. + final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId, + name); - Setting setting = mSettingsRegistry.getSettingLocked( - SettingsRegistry.SETTINGS_TYPE_SYSTEM, owningUserId, name); - appendSettingToCursor(result, setting); - } + Setting setting = mSettingsRegistry.getSettingLocked( + SettingsRegistry.SETTINGS_TYPE_SYSTEM, owningUserId, name); + appendSettingToCursor(result, setting); + } - return result; + return result; + } } - private Setting getSystemSettingLocked(String name, int requestingUserId) { + private Setting getSystemSetting(String name, int requestingUserId) { if (DEBUG) { Slog.v(LOG_TAG, "getSystemSetting(" + name + ", " + requestingUserId + ")"); } @@ -849,37 +863,39 @@ public class SettingsProvider extends ContentProvider { final int owningUserId = resolveOwningUserIdForSystemSettingLocked(callingUserId, name); // Get the value. - return mSettingsRegistry.getSettingLocked(SettingsRegistry.SETTINGS_TYPE_SYSTEM, - owningUserId, name); + synchronized (mLock) { + return mSettingsRegistry.getSettingLocked(SettingsRegistry.SETTINGS_TYPE_SYSTEM, + owningUserId, name); + } } - private boolean insertSystemSettingLocked(String name, String value, int requestingUserId) { + private boolean insertSystemSetting(String name, String value, int requestingUserId) { if (DEBUG) { - Slog.v(LOG_TAG, "insertSystemSettingLocked(" + name + ", " + value + ", " + Slog.v(LOG_TAG, "insertSystemSetting(" + name + ", " + value + ", " + requestingUserId + ")"); } - return mutateSystemSettingLocked(name, value, requestingUserId, MUTATION_OPERATION_INSERT); + return mutateSystemSetting(name, value, requestingUserId, MUTATION_OPERATION_INSERT); } - private boolean deleteSystemSettingLocked(String name, int requestingUserId) { + private boolean deleteSystemSetting(String name, int requestingUserId) { if (DEBUG) { - Slog.v(LOG_TAG, "deleteSystemSettingLocked(" + name + ", " + requestingUserId + ")"); + Slog.v(LOG_TAG, "deleteSystemSetting(" + name + ", " + requestingUserId + ")"); } - return mutateSystemSettingLocked(name, null, requestingUserId, MUTATION_OPERATION_DELETE); + return mutateSystemSetting(name, null, requestingUserId, MUTATION_OPERATION_DELETE); } - private boolean updateSystemSettingLocked(String name, String value, int requestingUserId) { + private boolean updateSystemSetting(String name, String value, int requestingUserId) { if (DEBUG) { - Slog.v(LOG_TAG, "updateSystemSettingLocked(" + name + ", " + value + ", " + Slog.v(LOG_TAG, "updateSystemSetting(" + name + ", " + value + ", " + requestingUserId + ")"); } - return mutateSystemSettingLocked(name, value, requestingUserId, MUTATION_OPERATION_UPDATE); + return mutateSystemSetting(name, value, requestingUserId, MUTATION_OPERATION_UPDATE); } - private boolean mutateSystemSettingLocked(String name, String value, int runAsUserId, + private boolean mutateSystemSetting(String name, String value, int runAsUserId, int operation) { // Make sure the caller can change the settings. enforceWritePermission(Manifest.permission.WRITE_SETTINGS); @@ -904,27 +920,31 @@ public class SettingsProvider extends ContentProvider { } // Mutate the value. - switch (operation) { - case MUTATION_OPERATION_INSERT: { - validateSystemSettingValue(name, value); - return mSettingsRegistry.insertSettingLocked(SettingsRegistry.SETTINGS_TYPE_SYSTEM, - owningUserId, name, value, getCallingPackage()); - } + synchronized (mLock) { + switch (operation) { + case MUTATION_OPERATION_INSERT: { + validateSystemSettingValue(name, value); + return mSettingsRegistry + .insertSettingLocked(SettingsRegistry.SETTINGS_TYPE_SYSTEM, + owningUserId, name, value, getCallingPackage()); + } - case MUTATION_OPERATION_DELETE: { - return mSettingsRegistry.deleteSettingLocked( - SettingsRegistry.SETTINGS_TYPE_SYSTEM, - owningUserId, name); - } + case MUTATION_OPERATION_DELETE: { + return mSettingsRegistry.deleteSettingLocked( + SettingsRegistry.SETTINGS_TYPE_SYSTEM, + owningUserId, name); + } - case MUTATION_OPERATION_UPDATE: { - validateSystemSettingValue(name, value); - return mSettingsRegistry.updateSettingLocked(SettingsRegistry.SETTINGS_TYPE_SYSTEM, - owningUserId, name, value, getCallingPackage()); + case MUTATION_OPERATION_UPDATE: { + validateSystemSettingValue(name, value); + return mSettingsRegistry + .updateSettingLocked(SettingsRegistry.SETTINGS_TYPE_SYSTEM, + owningUserId, name, value, getCallingPackage()); + } } - } - return false; + return false; + } } private void validateSystemSettingValue(String name, String value) { @@ -1043,6 +1063,7 @@ public class SettingsProvider extends ContentProvider { // user info is a cached instance, so just look up instead of cache. final long identity = Binder.clearCallingIdentity(); try { + // Just a lookup and not reentrant, so holding a lock is fine. UserInfo userInfo = mUserManager.getProfileParent(userId); return (userInfo != null) ? userInfo.id : userId; } finally { @@ -1088,7 +1109,7 @@ public class SettingsProvider extends ContentProvider { // skip prefix value = value.substring(1); - Setting settingValue = getSecureSettingLocked( + Setting settingValue = getSecureSetting( Settings.Secure.LOCATION_PROVIDERS_ALLOWED, owningUserId); String oldProviders = (settingValue != null) ? settingValue.getValue() : ""; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ObservableScrollView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ObservableScrollView.java index 1186a33..9e5cefd 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ObservableScrollView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ObservableScrollView.java @@ -99,7 +99,7 @@ public class ObservableScrollView extends ScrollView { } else if (!mTouchEnabled) { MotionEvent cancel = MotionEvent.obtain(ev); cancel.setAction(MotionEvent.ACTION_CANCEL); - super.dispatchTouchEvent(ev); + super.dispatchTouchEvent(cancel); cancel.recycle(); mTouchCancelled = true; return false; diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java index 01cc2ca..ff8fb83 100644 --- a/services/backup/java/com/android/server/backup/BackupManagerService.java +++ b/services/backup/java/com/android/server/backup/BackupManagerService.java @@ -88,13 +88,13 @@ import android.util.Slog; import android.util.SparseArray; import android.util.StringBuilderPrinter; +import com.android.internal.annotations.GuardedBy; import com.android.internal.backup.IBackupTransport; import com.android.internal.backup.IObbBackupService; import com.android.server.AppWidgetBackupBridge; import com.android.server.EventLogTags; import com.android.server.SystemService; import com.android.server.backup.PackageManagerBackupAgent.Metadata; -import com.android.server.pm.PackageManagerService; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; @@ -589,8 +589,12 @@ public class BackupManagerService { File mFullBackupScheduleFile; // If we're running a schedule-driven full backup, this is the task instance doing it - PerformFullTransportBackupTask mRunningFullBackupTask; // inside mQueueLock - ArrayList<FullBackupEntry> mFullBackupQueue; // inside mQueueLock + + @GuardedBy("mQueueLock") + PerformFullTransportBackupTask mRunningFullBackupTask; + + @GuardedBy("mQueueLock") + ArrayList<FullBackupEntry> mFullBackupQueue; // Utility: build a new random integer token int generateToken() { @@ -1229,8 +1233,10 @@ public class BackupManagerService { } } - // Resume the full-data backup queue - mFullBackupQueue = readFullBackupSchedule(); + synchronized (mQueueLock) { + // Resume the full-data backup queue + mFullBackupQueue = readFullBackupSchedule(); + } // Register for broadcasts about package install, etc., so we can // update the provider list. @@ -1248,74 +1254,98 @@ public class BackupManagerService { } private ArrayList<FullBackupEntry> readFullBackupSchedule() { + boolean changed = false; ArrayList<FullBackupEntry> schedule = null; - synchronized (mQueueLock) { - if (mFullBackupScheduleFile.exists()) { - FileInputStream fstream = null; - BufferedInputStream bufStream = null; - DataInputStream in = null; - try { - fstream = new FileInputStream(mFullBackupScheduleFile); - bufStream = new BufferedInputStream(fstream); - in = new DataInputStream(bufStream); + List<PackageInfo> apps = + PackageManagerBackupAgent.getStorableApplications(mPackageManager); - int version = in.readInt(); - if (version != SCHEDULE_FILE_VERSION) { - Slog.e(TAG, "Unknown backup schedule version " + version); - return null; - } + if (mFullBackupScheduleFile.exists()) { + FileInputStream fstream = null; + BufferedInputStream bufStream = null; + DataInputStream in = null; + try { + fstream = new FileInputStream(mFullBackupScheduleFile); + bufStream = new BufferedInputStream(fstream); + in = new DataInputStream(bufStream); - int N = in.readInt(); - schedule = new ArrayList<FullBackupEntry>(N); - for (int i = 0; i < N; i++) { - String pkgName = in.readUTF(); - long lastBackup = in.readLong(); - try { - PackageInfo pkg = mPackageManager.getPackageInfo(pkgName, 0); - if (appGetsFullBackup(pkg) - && appIsEligibleForBackup(pkg.applicationInfo)) { - schedule.add(new FullBackupEntry(pkgName, lastBackup)); - } else { - if (DEBUG) { - Slog.i(TAG, "Package " + pkgName - + " no longer eligible for full backup"); - } - } - } catch (NameNotFoundException e) { + int version = in.readInt(); + if (version != SCHEDULE_FILE_VERSION) { + Slog.e(TAG, "Unknown backup schedule version " + version); + return null; + } + + final int N = in.readInt(); + schedule = new ArrayList<FullBackupEntry>(N); + + // HashSet instead of ArraySet specifically because we want the eventual + // lookups against O(hundreds) of entries to be as fast as possible, and + // we discard the set immediately after the scan so the extra memory + // overhead is transient. + HashSet<String> foundApps = new HashSet<String>(N); + + for (int i = 0; i < N; i++) { + String pkgName = in.readUTF(); + long lastBackup = in.readLong(); + foundApps.add(pkgName); // all apps that we've addressed already + try { + PackageInfo pkg = mPackageManager.getPackageInfo(pkgName, 0); + if (appGetsFullBackup(pkg) && appIsEligibleForBackup(pkg.applicationInfo)) { + schedule.add(new FullBackupEntry(pkgName, lastBackup)); + } else { if (DEBUG) { Slog.i(TAG, "Package " + pkgName - + " not installed; dropping from full backup"); + + " no longer eligible for full backup"); } } + } catch (NameNotFoundException e) { + if (DEBUG) { + Slog.i(TAG, "Package " + pkgName + + " not installed; dropping from full backup"); + } } - Collections.sort(schedule); - } catch (Exception e) { - Slog.e(TAG, "Unable to read backup schedule", e); - mFullBackupScheduleFile.delete(); - schedule = null; - } finally { - IoUtils.closeQuietly(in); - IoUtils.closeQuietly(bufStream); - IoUtils.closeQuietly(fstream); } - } - if (schedule == null) { - // no prior queue record, or unable to read it. Set up the queue - // from scratch. - List<PackageInfo> apps = - PackageManagerBackupAgent.getStorableApplications(mPackageManager); - final int N = apps.size(); - schedule = new ArrayList<FullBackupEntry>(N); - for (int i = 0; i < N; i++) { - PackageInfo info = apps.get(i); - if (appGetsFullBackup(info) && appIsEligibleForBackup(info.applicationInfo)) { - schedule.add(new FullBackupEntry(info.packageName, 0)); + // New apps can arrive "out of band" via OTA and similar, so we also need to + // scan to make sure that we're tracking all full-backup candidates properly + for (PackageInfo app : apps) { + if (appGetsFullBackup(app) && appIsEligibleForBackup(app.applicationInfo)) { + if (!foundApps.contains(app.packageName)) { + if (DEBUG) { + Slog.i(TAG, "New full backup app " + app.packageName + " found"); + } + schedule.add(new FullBackupEntry(app.packageName, 0)); + changed = true; + } } } - writeFullBackupScheduleAsync(); + + Collections.sort(schedule); + } catch (Exception e) { + Slog.e(TAG, "Unable to read backup schedule", e); + mFullBackupScheduleFile.delete(); + schedule = null; + } finally { + IoUtils.closeQuietly(in); + IoUtils.closeQuietly(bufStream); + IoUtils.closeQuietly(fstream); + } + } + + if (schedule == null) { + // no prior queue record, or unable to read it. Set up the queue + // from scratch. + changed = true; + schedule = new ArrayList<FullBackupEntry>(apps.size()); + for (PackageInfo info : apps) { + if (appGetsFullBackup(info) && appIsEligibleForBackup(info.applicationInfo)) { + schedule.add(new FullBackupEntry(info.packageName, 0)); + } } } + + if (changed) { + writeFullBackupScheduleAsync(); + } return schedule; } @@ -4313,13 +4343,16 @@ public class BackupManagerService { // This is also slow but easy for modest numbers of apps: work backwards // from the end of the queue until we find an item whose last backup - // time was before this one, then insert this new entry after it. - int which; - for (which = mFullBackupQueue.size() - 1; which >= 0; which--) { - final FullBackupEntry entry = mFullBackupQueue.get(which); - if (entry.lastBackup <= lastBackedUp) { - mFullBackupQueue.add(which + 1, newEntry); - break; + // time was before this one, then insert this new entry after it. If we're + // adding something new we don't bother scanning, and just prepend. + int which = -1; + if (lastBackedUp > 0) { + for (which = mFullBackupQueue.size() - 1; which >= 0; which--) { + final FullBackupEntry entry = mFullBackupQueue.get(which); + if (entry.lastBackup <= lastBackedUp) { + mFullBackupQueue.add(which + 1, newEntry); + break; + } } } if (which < 0) { diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 6842304..5a9b5b2 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -8884,7 +8884,8 @@ public final class ActivityManagerService extends ActivityManagerNative throw new SecurityException("updateLockTaskPackage called from non-system process"); } synchronized (this) { - if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Whitelisting " + userId + ":" + packages); + if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "Whitelisting " + userId + ":" + + Arrays.toString(packages)); mLockTaskPackages.put(userId, packages); mStackSupervisor.onLockTaskPackagesUpdatedLocked(); } @@ -8927,7 +8928,7 @@ public final class ActivityManagerService extends ActivityManagerNative mStackSupervisor.setLockTaskModeLocked(task, isSystemInitiated ? ActivityManager.LOCK_TASK_MODE_PINNED : ActivityManager.LOCK_TASK_MODE_LOCKED, - "startLockTask"); + "startLockTask", true); } finally { Binder.restoreCallingIdentity(ident); } @@ -8992,7 +8993,7 @@ public final class ActivityManagerService extends ActivityManagerNative // Stop lock task synchronized (this) { mStackSupervisor.setLockTaskModeLocked(null, ActivityManager.LOCK_TASK_MODE_NONE, - "stopLockTask"); + "stopLockTask", true); } } finally { Binder.restoreCallingIdentity(ident); @@ -19433,7 +19434,7 @@ public final class ActivityManagerService extends ActivityManagerNative } mStackSupervisor.setLockTaskModeLocked(null, ActivityManager.LOCK_TASK_MODE_NONE, - "startUser"); + "startUser", false); final UserInfo userInfo = getUserManagerLocked().getUserInfo(userId); if (userInfo == null) { diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index f304828..5eee34f 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -1185,7 +1185,7 @@ public final class ActivityStackSupervisor implements DisplayListener { final TaskRecord task = r.task; if (task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE) { - setLockTaskModeLocked(task, LOCK_TASK_MODE_LOCKED, "mLockTaskAuth==LAUNCHABLE"); + setLockTaskModeLocked(task, LOCK_TASK_MODE_LOCKED, "mLockTaskAuth==LAUNCHABLE", false); } final ActivityStack stack = task.stack; @@ -3675,7 +3675,11 @@ public final class ActivityStackSupervisor implements DisplayListener { } void removeLockedTaskLocked(final TaskRecord task) { - if (mLockTaskModeTasks.remove(task) && mLockTaskModeTasks.isEmpty()) { + if (!mLockTaskModeTasks.remove(task)) { + return; + } + if (DEBUG_LOCKTASK) Slog.w(TAG_LOCKTASK, "removeLockedTaskLocked: removed " + task); + if (mLockTaskModeTasks.isEmpty()) { // Last one. if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "removeLockedTask: task=" + task + " last task, reverting locktask mode. Callers=" + Debug.getCallers(3)); @@ -3696,7 +3700,8 @@ public final class ActivityStackSupervisor implements DisplayListener { } } - void setLockTaskModeLocked(TaskRecord task, int lockTaskModeState, String reason) { + void setLockTaskModeLocked(TaskRecord task, int lockTaskModeState, String reason, + boolean andResume) { if (task == null) { // Take out of lock task mode if necessary final TaskRecord lockedTask = getLockedTaskLocked(); @@ -3745,8 +3750,11 @@ public final class ActivityStackSupervisor implements DisplayListener { if (task.mLockTaskUid == -1) { task.mLockTaskUid = task.mCallingUid; } - findTaskToMoveToFrontLocked(task, 0, null, reason); - resumeTopActivitiesLocked(); + + if (andResume) { + findTaskToMoveToFrontLocked(task, 0, null, reason); + resumeTopActivitiesLocked(); + } } boolean isLockTaskModeViolation(TaskRecord task) { @@ -3780,6 +3788,8 @@ public final class ActivityStackSupervisor implements DisplayListener { lockedTask.setLockTaskAuth(); if (wasLaunchable && lockedTask.mLockTaskAuth != LOCK_TASK_AUTH_LAUNCHABLE) { // Lost whitelisting authorization. End it now. + if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "onLockTaskPackagesUpdated: removing " + + lockedTask + " mLockTaskAuth=" + lockedTask.lockTaskAuthToString()); removeLockedTaskLocked(lockedTask); lockedTask.performClearTaskLocked(); didSomething = true; @@ -3797,7 +3807,11 @@ public final class ActivityStackSupervisor implements DisplayListener { if (mLockTaskModeTasks.isEmpty() && task != null && task.mLockTaskAuth == LOCK_TASK_AUTH_LAUNCHABLE) { // This task must have just been authorized. - setLockTaskModeLocked(task, ActivityManager.LOCK_TASK_MODE_LOCKED, "package updated"); + if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, + "onLockTaskPackagesUpdated: starting new locktask task=" + task); + setLockTaskModeLocked(task, ActivityManager.LOCK_TASK_MODE_LOCKED, "package updated", + false); + didSomething = true; } if (didSomething) { resumeTopActivitiesLocked(); diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java index 417c7c3..d56a024 100644 --- a/services/core/java/com/android/server/am/TaskRecord.java +++ b/services/core/java/com/android/server/am/TaskRecord.java @@ -739,38 +739,40 @@ final class TaskRecord { performClearTaskAtIndexLocked(0); } + String lockTaskAuthToString() { + switch (mLockTaskAuth) { + case LOCK_TASK_AUTH_DONT_LOCK: return "LOCK_TASK_AUTH_DONT_LOCK"; + case LOCK_TASK_AUTH_PINNABLE: return "LOCK_TASK_AUTH_PINNABLE"; + case LOCK_TASK_AUTH_LAUNCHABLE: return "LOCK_TASK_AUTH_LAUNCHABLE"; + case LOCK_TASK_AUTH_WHITELISTED: return "LOCK_TASK_AUTH_WHITELISTED"; + default: return "unknown=" + mLockTaskAuth; + } + } + void setLockTaskAuth() { switch (mLockTaskMode) { case LOCK_TASK_LAUNCH_MODE_DEFAULT: - if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this + - " mLockTaskAuth=" + (isLockTaskWhitelistedLocked() ? - "WHITELISTED" : "PINNABLE")); mLockTaskAuth = isLockTaskWhitelistedLocked() ? LOCK_TASK_AUTH_WHITELISTED : LOCK_TASK_AUTH_PINNABLE; break; case LOCK_TASK_LAUNCH_MODE_NEVER: - if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this + - " mLockTaskAuth=" + (mPrivileged ? "DONT_LOCK" : "PINNABLE")); mLockTaskAuth = mPrivileged ? LOCK_TASK_AUTH_DONT_LOCK : LOCK_TASK_AUTH_PINNABLE; break; case LOCK_TASK_LAUNCH_MODE_ALWAYS: - if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this + - " mLockTaskAuth=" + (mPrivileged ? "LAUNCHABLE" : "PINNABLE")); mLockTaskAuth = mPrivileged ? LOCK_TASK_AUTH_LAUNCHABLE: LOCK_TASK_AUTH_PINNABLE; break; case LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED: - if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this + - " mLockTaskAuth=" + (isLockTaskWhitelistedLocked() ? - "LAUNCHABLE" : "PINNABLE")); mLockTaskAuth = isLockTaskWhitelistedLocked() ? LOCK_TASK_AUTH_LAUNCHABLE : LOCK_TASK_AUTH_PINNABLE; break; } + if (DEBUG_LOCKTASK) Slog.d(TAG_LOCKTASK, "setLockTaskAuth: task=" + this + + " mLockTaskAuth=" + lockTaskAuthToString()); } boolean isLockTaskWhitelistedLocked() { @@ -1173,10 +1175,12 @@ final class TaskRecord { pw.print(" taskType="); pw.print(taskType); pw.print(" mTaskToReturnTo="); pw.println(mTaskToReturnTo); } - if (rootWasReset || mNeverRelinquishIdentity || mReuseTask) { + if (rootWasReset || mNeverRelinquishIdentity || mReuseTask + || mLockTaskAuth != LOCK_TASK_AUTH_PINNABLE) { pw.print(prefix); pw.print("rootWasReset="); pw.print(rootWasReset); pw.print(" mNeverRelinquishIdentity="); pw.print(mNeverRelinquishIdentity); - pw.print(" mReuseTask="); pw.println(mReuseTask); + pw.print(" mReuseTask="); pw.print(mReuseTask); + pw.print(" mLockTaskAuth="); pw.println(lockTaskAuthToString()); } if (mAffiliatedTaskId != taskId || mPrevAffiliateTaskId != INVALID_TASK_ID || mPrevAffiliate != null || mNextAffiliateTaskId != INVALID_TASK_ID diff --git a/services/core/java/com/android/server/fingerprint/FingerprintService.java b/services/core/java/com/android/server/fingerprint/FingerprintService.java index d725d94..1057ce3 100644 --- a/services/core/java/com/android/server/fingerprint/FingerprintService.java +++ b/services/core/java/com/android/server/fingerprint/FingerprintService.java @@ -30,6 +30,7 @@ import android.os.IRemoteCallback; import android.os.Looper; import android.os.MessageQueue; import android.os.RemoteException; +import android.os.ServiceManager; import android.util.Slog; import com.android.server.SystemService; @@ -37,6 +38,8 @@ import com.android.server.SystemService; import android.hardware.fingerprint.Fingerprint; import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.IFingerprintService; +import android.hardware.fingerprint.IFingerprintDaemon; +import android.hardware.fingerprint.IFingerprintDaemonCallback; import android.hardware.fingerprint.IFingerprintServiceReceiver; import static android.Manifest.permission.MANAGE_FINGERPRINT; @@ -55,20 +58,19 @@ import java.util.List; * * @hide */ -public class FingerprintService extends SystemService { +public class FingerprintService extends SystemService implements IBinder.DeathRecipient { private static final String TAG = "FingerprintService"; private static final boolean DEBUG = true; + private static final String FP_DATA_DIR = "fpdata"; + private static final String FINGERPRINTD = "android.hardware.fingerprint.IFingerprintDaemon"; + private static final int MSG_USER_SWITCHING = 10; + private static final int ENROLLMENT_TIMEOUT_MS = 60 * 1000; // 1 minute + private ClientMonitor mAuthClient = null; private ClientMonitor mEnrollClient = null; private ClientMonitor mRemoveClient = null; - private final AppOpsManager mAppOps; - private static final int MSG_NOTIFY = 10; - private static final int MSG_USER_SWITCHING = 11; - - private static final int ENROLLMENT_TIMEOUT_MS = 60 * 1000; // 1 minute - // Message types. Used internally to dispatch messages to the correct callback. // Must agree with the list in fingerprint.h private static final int FINGERPRINT_ERROR = -1; @@ -83,11 +85,6 @@ public class FingerprintService extends SystemService { Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { - case MSG_NOTIFY: - FpHalMsg m = (FpHalMsg) msg.obj; - handleNotify(m.type, m.arg1, m.arg2, m.arg3); - break; - case MSG_USER_SWITCHING: handleUserSwitching(msg.arg1); break; @@ -97,10 +94,13 @@ public class FingerprintService extends SystemService { } } }; + + private final FingerprintUtils mFingerprintUtils = FingerprintUtils.getInstance(); private Context mContext; - private int mHalDeviceId; + private long mHalDeviceId; private int mFailedAttempts; - private final FingerprintUtils mFingerprintUtils = FingerprintUtils.getInstance(); + private IFingerprintDaemon mDaemon; + private final Runnable mLockoutReset = new Runnable() { @Override public void run() { @@ -112,127 +112,115 @@ public class FingerprintService extends SystemService { super(context); mContext = context; mAppOps = context.getSystemService(AppOpsManager.class); - nativeInit(Looper.getMainLooper().getQueue(), this); - } - - // TODO: Move these into separate process - // JNI methods to communicate from FingerprintService to HAL - static native int nativeEnroll(byte [] token, int groupId, int timeout); - static native long nativePreEnroll(); - static native int nativeStopEnrollment(); - static native int nativeAuthenticate(long sessionId, int groupId); - static native int nativeStopAuthentication(); - static native int nativeRemove(int fingerId, int groupId); - static native int nativeOpenHal(); - static native int nativeCloseHal(); - static native void nativeInit(MessageQueue queue, FingerprintService service); - static native long nativeGetAuthenticatorId(); - static native int nativeSetActiveGroup(int gid, byte[] storePath); - - static final class FpHalMsg { - int type; // Type of the message. One of the constants in fingerprint.h - int arg1; // optional arguments - int arg2; - int arg3; - - FpHalMsg(int type, int arg1, int arg2, int arg3) { - this.type = type; - this.arg1 = arg1; - this.arg2 = arg2; - this.arg3 = arg3; - } - } - - /** - * Called from JNI to communicate messages from fingerprint HAL. - */ - void notify(int type, int arg1, int arg2, int arg3) { - mHandler.obtainMessage(MSG_NOTIFY, new FpHalMsg(type, arg1, arg2, arg3)).sendToTarget(); - } - - void handleNotify(int type, int arg1, int arg2, int arg3) { - Slog.v(TAG, "handleNotify(type=" + type + ", arg1=" + arg1 + ", arg2=" + arg2 + ")" - + ", mAuthClients = " + mAuthClient + ", mEnrollClient = " + mEnrollClient); + } + + @Override + public void binderDied() { + Slog.v(TAG, "fingerprintd died"); + mDaemon = null; + } + + public IFingerprintDaemon getFingerprintDaemon() { + if (mDaemon == null) { + mDaemon = IFingerprintDaemon.Stub.asInterface(ServiceManager.getService(FINGERPRINTD)); + if (mDaemon == null) { + Slog.w(TAG, "fingerprind service not available"); + } else { + try { + mDaemon.asBinder().linkToDeath(this, 0); + } catch (RemoteException e) { + Slog.w(TAG, "caught remote exception in linkToDeath: ", e); + mDaemon = null; // try again! + } + } + } + return mDaemon; + } + + protected void dispatchEnumerate(long deviceId, int[] fingerIds, int[] groupIds) { + if (fingerIds.length != groupIds.length) { + Slog.w(TAG, "fingerIds and groupIds differ in length: f[]=" + + fingerIds + ", g[]=" + groupIds); + return; + } + if (DEBUG) Slog.w(TAG, "Enumerate: f[]=" + fingerIds + ", g[]=" + groupIds); + // TODO: update fingerprint/name pairs + } + + protected void dispatchRemoved(long deviceId, int fingerId, int groupId) { + final ClientMonitor client = mRemoveClient; + if (fingerId != 0) { + ContentResolver res = mContext.getContentResolver(); + removeTemplateForUser(mRemoveClient, fingerId); + } + if (client != null && client.sendRemoved(fingerId, groupId)) { + removeClient(mRemoveClient); + } + } + + protected void dispatchError(long deviceId, int error) { if (mEnrollClient != null) { final IBinder token = mEnrollClient.token; - if (dispatchNotify(mEnrollClient, type, arg1, arg2, arg3)) { + if (mEnrollClient.sendError(error)) { stopEnrollment(token, false); - removeClient(mEnrollClient); } + } else if (mAuthClient != null) { + final IBinder token = mAuthClient.token; + if (mAuthClient.sendError(error)) { + stopAuthentication(token, false); + } + } else if (mRemoveClient != null) { + if (mRemoveClient.sendError(error)) removeClient(mRemoveClient); } + } + + protected void dispatchAuthenticated(long deviceId, int fingerId, int groupId) { if (mAuthClient != null) { final IBinder token = mAuthClient.token; - if (dispatchNotify(mAuthClient, type, arg1, arg2, arg3)) { + if (mAuthClient.sendAuthenticated(fingerId, groupId)) { stopAuthentication(token, false); removeClient(mAuthClient); } } - if (mRemoveClient != null) { - if (dispatchNotify(mRemoveClient, type, arg1, arg2, arg3)) { - removeClient(mRemoveClient); + } + + protected void dispatchAcquired(long deviceId, int acquiredInfo) { + if (mEnrollClient != null) { + if (mEnrollClient.sendAcquired(acquiredInfo)) { + removeClient(mEnrollClient); + } + } else if (mAuthClient != null) { + if (mAuthClient.sendAcquired(acquiredInfo)) { + removeClient(mAuthClient); } } + } void handleUserSwitching(int userId) { updateActiveGroup(userId); } - /* - * Dispatch notify events to clients. - * - * @return true if the operation is done, i.e. authentication completed - */ - boolean dispatchNotify(ClientMonitor clientMonitor, int type, int arg1, int arg2, int arg3) { - boolean operationCompleted = false; - int fpId; - int groupId; - int remaining; - int acquireInfo; - switch (type) { - case FINGERPRINT_ERROR: - fpId = arg1; - operationCompleted = clientMonitor.sendError(fpId); - break; - case FINGERPRINT_ACQUIRED: - acquireInfo = arg1; - operationCompleted = clientMonitor.sendAcquired(acquireInfo); - break; - case FINGERPRINT_AUTHENTICATED: - fpId = arg1; - groupId = arg2; - operationCompleted = clientMonitor.sendAuthenticated(fpId, groupId); - break; - case FINGERPRINT_TEMPLATE_ENROLLING: - fpId = arg1; - groupId = arg2; - remaining = arg3; - operationCompleted = clientMonitor.sendEnrollResult(fpId, groupId, remaining); + protected void dispatchEnrollResult(long deviceId, int fingerId, int groupId, int remaining) { + if (mEnrollClient != null) { + if (mEnrollClient.sendEnrollResult(fingerId, groupId, remaining)) { if (remaining == 0) { - addTemplateForUser(clientMonitor, fpId); - operationCompleted = true; // enroll completed - } - break; - case FINGERPRINT_TEMPLATE_REMOVED: - fpId = arg1; - groupId = arg2; - operationCompleted = clientMonitor.sendRemoved(fpId, groupId); - if (fpId != 0) { - removeTemplateForUser(clientMonitor, fpId); + ContentResolver res = mContext.getContentResolver(); + addTemplateForUser(mEnrollClient, fingerId); + removeClient(mEnrollClient); } - break; + } } - return operationCompleted; } - private void removeClient(ClientMonitor clientMonitor) { - if (clientMonitor == null) return; - clientMonitor.destroy(); - if (clientMonitor == mAuthClient) { + private void removeClient(ClientMonitor client) { + if (client == null) return; + client.destroy(); + if (client == mAuthClient) { mAuthClient = null; - } else if (clientMonitor == mEnrollClient) { + } else if (client == mEnrollClient) { mEnrollClient = null; - } else if (clientMonitor == mRemoveClient) { + } else if (client == mRemoveClient) { mRemoveClient = null; } } @@ -273,17 +261,36 @@ public class FingerprintService extends SystemService { void startEnrollment(IBinder token, byte[] cryptoToken, int groupId, IFingerprintServiceReceiver receiver, int flags) { + IFingerprintDaemon daemon = getFingerprintDaemon(); + if (daemon == null) { + Slog.w(TAG, "enroll: no fingeprintd!"); + return; + } stopPendingOperations(); mEnrollClient = new ClientMonitor(token, receiver, groupId); final int timeout = (int) (ENROLLMENT_TIMEOUT_MS / MS_PER_SEC); - final int result = nativeEnroll(cryptoToken, groupId, timeout); - if (result != 0) { - Slog.w(TAG, "startEnroll failed, result=" + result); + try { + final int result = daemon.enroll(cryptoToken, groupId, timeout); + if (result != 0) { + Slog.w(TAG, "startEnroll failed, result=" + result); + } + } catch (RemoteException e) { + Slog.e(TAG, "startEnroll failed", e); } } public long startPreEnroll(IBinder token) { - return nativePreEnroll(); + IFingerprintDaemon daemon = getFingerprintDaemon(); + if (daemon == null) { + Slog.w(TAG, "startPreEnroll: no fingeprintd!"); + return 0; + } + try { + return daemon.preEnroll(); + } catch (RemoteException e) { + Slog.e(TAG, "startPreEnroll failed", e); + } + return 0; } private void stopPendingOperations() { @@ -297,20 +304,34 @@ public class FingerprintService extends SystemService { } void stopEnrollment(IBinder token, boolean notify) { + IFingerprintDaemon daemon = getFingerprintDaemon(); + if (daemon == null) { + Slog.w(TAG, "stopEnrollment: no fingeprintd!"); + return; + } final ClientMonitor client = mEnrollClient; if (client == null || client.token != token) return; - int result = nativeStopEnrollment(); + try { + int result = daemon.cancelEnrollment(); + if (result != 0) { + Slog.w(TAG, "startEnrollCancel failed, result = " + result); + } + } catch (RemoteException e) { + Slog.e(TAG, "stopEnrollment failed", e); + } if (notify) { client.sendError(FingerprintManager.FINGERPRINT_ERROR_CANCELED); } removeClient(mEnrollClient); - if (result != 0) { - Slog.w(TAG, "startEnrollCancel failed, result=" + result); - } } void startAuthentication(IBinder token, long opId, int groupId, IFingerprintServiceReceiver receiver, int flags) { + IFingerprintDaemon daemon = getFingerprintDaemon(); + if (daemon == null) { + Slog.w(TAG, "startAuthentication: no fingeprintd!"); + return; + } stopPendingOperations(); mAuthClient = new ClientMonitor(token, receiver, groupId); if (inLockoutMode()) { @@ -322,32 +343,54 @@ public class FingerprintService extends SystemService { return; } final int timeout = (int) (ENROLLMENT_TIMEOUT_MS / MS_PER_SEC); - final int result = nativeAuthenticate(opId, groupId); - if (result != 0) { - Slog.w(TAG, "startAuthentication failed, result=" + result); + try { + final int result = daemon.authenticate(opId, groupId); + if (result != 0) { + Slog.w(TAG, "startAuthentication failed, result=" + result); + } + } catch (RemoteException e) { + Slog.e(TAG, "startAuthentication failed", e); } } void stopAuthentication(IBinder token, boolean notify) { + IFingerprintDaemon daemon = getFingerprintDaemon(); + if (daemon == null) { + Slog.w(TAG, "stopAuthentication: no fingeprintd!"); + return; + } final ClientMonitor client = mAuthClient; if (client == null || client.token != token) return; - int result = nativeStopAuthentication(); + try { + int result = daemon.cancelAuthentication(); + if (result != 0) { + Slog.w(TAG, "stopAuthentication failed, result=" + result); + } + } catch (RemoteException e) { + Slog.e(TAG, "stopAuthentication failed", e); + } if (notify) { client.sendError(FingerprintManager.FINGERPRINT_ERROR_CANCELED); } removeClient(mAuthClient); - if (result != 0) { - Slog.w(TAG, "stopAuthentication failed, result=" + result); - } } void startRemove(IBinder token, int fingerId, int userId, IFingerprintServiceReceiver receiver) { + IFingerprintDaemon daemon = getFingerprintDaemon(); + if (daemon == null) { + Slog.w(TAG, "startRemove: no fingeprintd!"); + return; + } mRemoveClient = new ClientMonitor(token, receiver, userId); // The fingerprint template ids will be removed when we get confirmation from the HAL - final int result = nativeRemove(fingerId, userId); - if (result != 0) { - Slog.w(TAG, "startRemove with id = " + fingerId + " failed with result=" + result); + try { + final int result = daemon.remove(fingerId, userId); + if (result != 0) { + Slog.w(TAG, "startRemove with id = " + fingerId + " failed, result=" + result); + } + } catch (RemoteException e) { + Slog.e(TAG, "startRemove failed", e); } } @@ -364,7 +407,7 @@ public class FingerprintService extends SystemService { "Must have " + permission + " permission."); } - private boolean canUserFingerPrint(String opPackageName) { + private boolean canUseFingerprint(String opPackageName) { checkPermission(USE_FINGERPRINT); return mAppOps.noteOp(AppOpsManager.OP_USE_FINGERPRINT, Binder.getCallingUid(), @@ -496,15 +539,48 @@ public class FingerprintService extends SystemService { } } - private final class FingerprintServiceWrapper extends IFingerprintService.Stub { + private IFingerprintDaemonCallback mDaemonCallback = new IFingerprintDaemonCallback.Stub() { + + @Override + public void onEnrollResult(long deviceId, int fingerId, int groupId, int remaining) { + dispatchEnrollResult(deviceId, fingerId, groupId, remaining); + } + + @Override + public void onAcquired(long deviceId, int acquiredInfo) { + dispatchAcquired(deviceId, acquiredInfo); + } + + @Override + public void onAuthenticated(long deviceId, int fingerId, int groupId) { + dispatchAuthenticated(deviceId, fingerId, groupId); + } + + @Override + public void onError(long deviceId, int error) { + dispatchError(deviceId, error); + } + + @Override + public void onRemoved(long deviceId, int fingerId, int groupId) { + dispatchRemoved(deviceId, fingerId, groupId); + } + @Override + public void onEnumerate(long deviceId, int[] fingerIds, int[] groupIds) { + dispatchEnumerate(deviceId, fingerIds, groupIds); + } + + }; + + private final class FingerprintServiceWrapper extends IFingerprintService.Stub { + @Override // Binder call public long preEnroll(IBinder token) { checkPermission(MANAGE_FINGERPRINT); return startPreEnroll(token); } - @Override - // Binder call + @Override // Binder call public void enroll(final IBinder token, final byte[] cryptoToken, final int groupId, final IFingerprintServiceReceiver receiver, final int flags) { checkPermission(MANAGE_FINGERPRINT); @@ -517,8 +593,7 @@ public class FingerprintService extends SystemService { }); } - @Override - // Binder call + @Override // Binder call public void cancelEnrollment(final IBinder token) { checkPermission(MANAGE_FINGERPRINT); mHandler.post(new Runnable() { @@ -529,12 +604,11 @@ public class FingerprintService extends SystemService { }); } - @Override - // Binder call + @Override // Binder call public void authenticate(final IBinder token, final long opId, final int groupId, final IFingerprintServiceReceiver receiver, final int flags, String opPackageName) { checkPermission(USE_FINGERPRINT); - if (!canUserFingerPrint(opPackageName)) { + if (!canUseFingerprint(opPackageName)) { return; } mHandler.post(new Runnable() { @@ -545,11 +619,9 @@ public class FingerprintService extends SystemService { }); } - @Override - - // Binder call + @Override // Binder call public void cancelAuthentication(final IBinder token, String opPackageName) { - if (!canUserFingerPrint(opPackageName)) { + if (!canUseFingerprint(opPackageName)) { return; } mHandler.post(new Runnable() { @@ -560,8 +632,7 @@ public class FingerprintService extends SystemService { }); } - @Override - // Binder call + @Override // Binder call public void remove(final IBinder token, final int fingerId, final int groupId, final IFingerprintServiceReceiver receiver) { checkPermission(MANAGE_FINGERPRINT); // TODO: Maybe have another permission @@ -574,17 +645,15 @@ public class FingerprintService extends SystemService { } - @Override - // Binder call + @Override // Binder call public boolean isHardwareDetected(long deviceId, String opPackageName) { - if (!canUserFingerPrint(opPackageName)) { + if (!canUseFingerprint(opPackageName)) { return false; } - return mHalDeviceId != 0; // TODO + return mHalDeviceId != 0; } - @Override - // Binder call + @Override // Binder call public void rename(final int fingerId, final int groupId, final String name) { checkPermission(MANAGE_FINGERPRINT); mHandler.post(new Runnable() { @@ -595,69 +664,102 @@ public class FingerprintService extends SystemService { }); } - @Override - // Binder call + @Override // Binder call public List<Fingerprint> getEnrolledFingerprints(int groupId, String opPackageName) { - if (!canUserFingerPrint(opPackageName)) { + if (!canUseFingerprint(opPackageName)) { return Collections.emptyList(); } return FingerprintService.this.getEnrolledFingerprints(groupId); } - @Override - // Binder call + @Override // Binder call public boolean hasEnrolledFingerprints(int groupId, String opPackageName) { - if (!canUserFingerPrint(opPackageName)) { + if (!canUseFingerprint(opPackageName)) { return false; } return FingerprintService.this.hasEnrolledFingerprints(groupId); } - @Override + @Override // Binder call public long getAuthenticatorId(String opPackageName) { - if (!canUserFingerPrint(opPackageName)) { + if (!canUseFingerprint(opPackageName)) { return 0; } - return nativeGetAuthenticatorId(); + return FingerprintService.this.getAuthenticatorId(); } } @Override public void onStart() { publishBinderService(Context.FINGERPRINT_SERVICE, new FingerprintServiceWrapper()); - mHalDeviceId = nativeOpenHal(); - updateActiveGroup(ActivityManager.getCurrentUser()); + IFingerprintDaemon daemon = getFingerprintDaemon(); + if (daemon != null) { + try { + daemon.init(mDaemonCallback); + mHalDeviceId = daemon.openHal(); + updateActiveGroup(ActivityManager.getCurrentUser()); + } catch (RemoteException e) { + Slog.e(TAG, "Failed to open fingeprintd HAL", e); + } + } if (DEBUG) Slog.v(TAG, "Fingerprint HAL id: " + mHalDeviceId); listenForUserSwitches(); } private void updateActiveGroup(int userId) { - if (mHalDeviceId != 0) { - File path = Environment.getUserSystemDirectory(userId); - nativeSetActiveGroup(userId, path.getAbsolutePath().getBytes()); + IFingerprintDaemon daemon = getFingerprintDaemon(); + if (daemon != null) { + try { + // TODO: if this is a managed profile, use the profile parent's directory for + // storage. + final File systemDir = Environment.getUserSystemDirectory(userId); + final File fpDir = new File(systemDir, FP_DATA_DIR); + if (!fpDir.exists()) { + if (!fpDir.mkdir()) { + Slog.v(TAG, "Cannot make directory: " + fpDir.getAbsolutePath()); + return; + } + } + daemon.setActiveGroup(userId, fpDir.getAbsolutePath().getBytes()); + } catch (RemoteException e) { + Slog.e(TAG, "Failed to setActiveGroup():", e); + } } } private void listenForUserSwitches() { try { ActivityManagerNative.getDefault().registerUserSwitchObserver( - new IUserSwitchObserver.Stub() { - @Override - public void onUserSwitching(int newUserId, IRemoteCallback reply) { - mHandler.obtainMessage(MSG_USER_SWITCHING, newUserId, 0 /* unused */) - .sendToTarget(); - } - @Override - public void onUserSwitchComplete(int newUserId) throws RemoteException { - // Ignore. - } - @Override - public void onForegroundProfileSwitch(int newProfileId) { - // Ignore. - } - }); + new IUserSwitchObserver.Stub() { + @Override + public void onUserSwitching(int newUserId, IRemoteCallback reply) { + mHandler.obtainMessage(MSG_USER_SWITCHING, newUserId, 0 /* unused */) + .sendToTarget(); + } + @Override + public void onUserSwitchComplete(int newUserId) throws RemoteException { + // Ignore. + } + @Override + public void onForegroundProfileSwitch(int newProfileId) { + // Ignore. + } + }); } catch (RemoteException e) { Slog.w(TAG, "Failed to listen for user switching event" ,e); } } + + public long getAuthenticatorId() { + IFingerprintDaemon daemon = getFingerprintDaemon(); + if (daemon != null) { + try { + return daemon.getAuthenticatorId(); + } catch (RemoteException e) { + Slog.e(TAG, "getAuthenticatorId failed", e); + } + } + return 0; + } + } diff --git a/services/core/jni/Android.mk b/services/core/jni/Android.mk index a5546cf..9556b08 100644 --- a/services/core/jni/Android.mk +++ b/services/core/jni/Android.mk @@ -10,7 +10,6 @@ LOCAL_SRC_FILES += \ $(LOCAL_REL_DIR)/com_android_server_AssetAtlasService.cpp \ $(LOCAL_REL_DIR)/com_android_server_connectivity_Vpn.cpp \ $(LOCAL_REL_DIR)/com_android_server_ConsumerIrService.cpp \ - $(LOCAL_REL_DIR)/com_android_server_fingerprint_FingerprintService.cpp \ $(LOCAL_REL_DIR)/com_android_server_hdmi_HdmiCecController.cpp \ $(LOCAL_REL_DIR)/com_android_server_input_InputApplicationHandle.cpp \ $(LOCAL_REL_DIR)/com_android_server_input_InputManagerService.cpp \ diff --git a/services/core/jni/onload.cpp b/services/core/jni/onload.cpp index 7db7414..67872da 100644 --- a/services/core/jni/onload.cpp +++ b/services/core/jni/onload.cpp @@ -41,7 +41,6 @@ int register_android_server_connectivity_Vpn(JNIEnv* env); int register_android_server_hdmi_HdmiCecController(JNIEnv* env); int register_android_server_tv_TvInputHal(JNIEnv* env); int register_android_server_PersistentDataBlockService(JNIEnv* env); -int register_android_server_fingerprint_FingerprintService(JNIEnv* env); int register_android_server_Watchdog(JNIEnv* env); }; @@ -79,7 +78,6 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) register_android_server_hdmi_HdmiCecController(env); register_android_server_tv_TvInputHal(env); register_android_server_PersistentDataBlockService(env); - register_android_server_fingerprint_FingerprintService(env); register_android_server_Watchdog(env); return JNI_VERSION_1_4; diff --git a/services/usage/java/com/android/server/usage/IntervalStats.java b/services/usage/java/com/android/server/usage/IntervalStats.java index d6ff475..a615675 100644 --- a/services/usage/java/com/android/server/usage/IntervalStats.java +++ b/services/usage/java/com/android/server/usage/IntervalStats.java @@ -131,6 +131,11 @@ class IntervalStats { usageStats.mBeginIdleTime = timeStamp; } + void updateLastUsedTime(String packageName, long lastUsedTime) { + UsageStats usageStats = getOrCreateUsageStats(packageName); + usageStats.mLastTimeUsed = lastUsedTime; + } + void updateConfigurationStats(Configuration config, long timeStamp) { if (activeConfiguration != null) { ConfigurationStats activeStats = configurations.get(activeConfiguration); diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java index f7bcf2a..ff3bb28 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UsageStatsService.java @@ -99,7 +99,9 @@ public class UsageStatsService extends SystemService implements private static final long TIME_CHANGE_THRESHOLD_MILLIS = 2 * 1000; // Two seconds. static final long DEFAULT_APP_IDLE_THRESHOLD_MILLIS = DEBUG ? ONE_MINUTE * 4 - : 1L * 24 * 60 * ONE_MINUTE; // 1 day + : 12 * 60 * ONE_MINUTE; // 12 hours of screen-on time sans dream-time + static final long DEFAULT_WALLCLOCK_APP_IDLE_THRESHOLD_MILLIS = DEBUG ? ONE_MINUTE * 8 + : 2L * 24 * 60 * ONE_MINUTE; // 2 days static final long DEFAULT_CHECK_IDLE_INTERVAL = DEBUG ? ONE_MINUTE : 8 * 60 * ONE_MINUTE; // 8 hours static final long DEFAULT_PAROLE_INTERVAL = DEBUG ? ONE_MINUTE * 10 @@ -356,7 +358,7 @@ public class UsageStatsService extends SystemService implements final int packageCount = packages.size(); for (int p = 0; p < packageCount; p++) { final String packageName = packages.get(p).packageName; - final boolean isIdle = isAppIdleFiltered(packageName, userId); + final boolean isIdle = isAppIdleFiltered(packageName, userId, timeNow); mHandler.sendMessage(mHandler.obtainMessage(MSG_INFORM_LISTENERS, userId, isIdle ? 1 : 0, packageName)); mAppIdleHistory.addEntry(packageName, userId, isIdle, timeNow); @@ -386,7 +388,8 @@ public class UsageStatsService extends SystemService implements void updateDisplayLocked() { boolean screenOn = mDisplayManager.getDisplay(Display.DEFAULT_DISPLAY).getState() - != Display.STATE_OFF; + == Display.STATE_ON; + if (screenOn == mScreenOn) return; mScreenOn = screenOn; @@ -533,14 +536,16 @@ public class UsageStatsService extends SystemService implements void reportEvent(UsageEvents.Event event, int userId) { synchronized (mLock) { final long timeNow = checkAndGetTimeLocked(); + final long screenOnTime = getScreenOnTimeLocked(timeNow); convertToSystemTimeLocked(event); final UserUsageStatsService service = getUserDataAndInitializeIfNeededLocked(userId, timeNow); - final long lastUsed = service.getBeginIdleTime(event.mPackage); - final long screenOnTime = getScreenOnTimeLocked(timeNow); - final boolean previouslyIdle = hasPassedIdleTimeout(lastUsed, screenOnTime); - service.reportEvent(event, screenOnTime); + final long beginIdleTime = service.getBeginIdleTime(event.mPackage); + final long lastUsedTime = service.getLastUsedTime(event.mPackage); + final boolean previouslyIdle = hasPassedIdleTimeoutLocked(beginIdleTime, + lastUsedTime, screenOnTime, timeNow); + service.reportEvent(event, getScreenOnTimeLocked(timeNow)); // Inform listeners if necessary if ((event.mEventType == Event.MOVE_TO_FOREGROUND || event.mEventType == Event.MOVE_TO_BACKGROUND @@ -556,8 +561,9 @@ public class UsageStatsService extends SystemService implements } /** - * Forces the app's beginIdleTime to reflect idle or active. If idle, then it rolls back the - * beginIdleTime to a point in time thats behind the threshold for idle. + * Forces the app's beginIdleTime and lastUsedTime to reflect idle or active. If idle, + * then it rolls back the beginIdleTime and lastUsedTime to a point in time that's behind + * the threshold for idle. */ void forceIdleState(String packageName, int userId, boolean idle) { synchronized (mLock) { @@ -567,10 +573,13 @@ public class UsageStatsService extends SystemService implements final UserUsageStatsService service = getUserDataAndInitializeIfNeededLocked(userId, timeNow); - final long lastUsed = service.getBeginIdleTime(packageName); - final boolean previouslyIdle = hasPassedIdleTimeout(lastUsed, - getScreenOnTimeLocked(timeNow)); + final long beginIdleTime = service.getBeginIdleTime(packageName); + final long lastUsedTime = service.getLastUsedTime(packageName); + final boolean previouslyIdle = hasPassedIdleTimeoutLocked(beginIdleTime, + lastUsedTime, screenOnTime, timeNow); service.setBeginIdleTime(packageName, deviceUsageTime); + service.setLastUsedTime(packageName, + timeNow - (idle ? DEFAULT_WALLCLOCK_APP_IDLE_THRESHOLD_MILLIS : 0) - 5000); // Inform listeners if necessary if (previouslyIdle != idle) { // Slog.d(TAG, "Informing listeners of out-of-idle " + event.mPackage); @@ -650,13 +659,14 @@ public class UsageStatsService extends SystemService implements } } - private boolean isAppIdleUnfiltered(String packageName, int userId) { + private boolean isAppIdleUnfiltered(String packageName, int userId, long timeNow) { synchronized (mLock) { - final long timeNow = checkAndGetTimeLocked(); + final long screenOnTime = getScreenOnTimeLocked(timeNow); final UserUsageStatsService service = getUserDataAndInitializeIfNeededLocked(userId, timeNow); long beginIdleTime = service.getBeginIdleTime(packageName); - return hasPassedIdleTimeout(beginIdleTime, getScreenOnTimeLocked(timeNow)); + long lastUsedTime = service.getLastUsedTime(packageName); + return hasPassedIdleTimeoutLocked(beginIdleTime, lastUsedTime, screenOnTime, timeNow); } } @@ -665,8 +675,10 @@ public class UsageStatsService extends SystemService implements * @param currentTime current time in device usage timebase * @return whether it's been used far enough in the past to be considered inactive */ - boolean hasPassedIdleTimeout(long timestamp, long currentTime) { - return timestamp <= currentTime - mAppIdleDurationMillis; + boolean hasPassedIdleTimeoutLocked(long beginIdleTime, long lastUsedTime, + long screenOnTime, long currentTime) { + return (beginIdleTime <= screenOnTime - mAppIdleDurationMillis) + && (lastUsedTime <= currentTime - DEFAULT_WALLCLOCK_APP_IDLE_THRESHOLD_MILLIS); } void addListener(AppIdleStateChangeListener listener) { @@ -689,9 +701,12 @@ public class UsageStatsService extends SystemService implements * This happens if the device is plugged in or temporarily allowed to make exceptions. * Called by interface impls. */ - boolean isAppIdleFiltered(String packageName, int userId) { + boolean isAppIdleFiltered(String packageName, int userId, long timeNow) { if (packageName == null) return false; synchronized (mLock) { + if (timeNow == -1) { + timeNow = checkAndGetTimeLocked(); + } // Temporary exemption, probably due to device charging or occasional allowance to // be allowed to sync, etc. if (mAppIdleParoled) { @@ -715,7 +730,7 @@ public class UsageStatsService extends SystemService implements return false; } - return isAppIdleUnfiltered(packageName, userId); + return isAppIdleUnfiltered(packageName, userId, timeNow); } void setAppIdle(String packageName, boolean idle, int userId) { @@ -948,7 +963,7 @@ public class UsageStatsService extends SystemService implements } final long token = Binder.clearCallingIdentity(); try { - return UsageStatsService.this.isAppIdleFiltered(packageName, userId); + return UsageStatsService.this.isAppIdleFiltered(packageName, userId, -1); } finally { Binder.restoreCallingIdentity(token); } @@ -1053,7 +1068,7 @@ public class UsageStatsService extends SystemService implements @Override public boolean isAppIdle(String packageName, int userId) { - return UsageStatsService.this.isAppIdleFiltered(packageName, userId); + return UsageStatsService.this.isAppIdleFiltered(packageName, userId, -1); } @Override diff --git a/services/usage/java/com/android/server/usage/UserUsageStatsService.java b/services/usage/java/com/android/server/usage/UserUsageStatsService.java index b7e1c22..7c00dae 100644 --- a/services/usage/java/com/android/server/usage/UserUsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UserUsageStatsService.java @@ -216,12 +216,19 @@ class UserUsageStatsService { } /** - * Sets the last timestamp for each of the intervals. - * @param lastTimestamp + * Sets the beginIdleTime for each of the intervals. + * @param beginIdleTime */ - void setBeginIdleTime(String packageName, long deviceUsageTime) { + void setBeginIdleTime(String packageName, long beginIdleTime) { for (IntervalStats stats : mCurrentStats) { - stats.updateBeginIdleTime(packageName, deviceUsageTime); + stats.updateBeginIdleTime(packageName, beginIdleTime); + } + notifyStatsChanged(); + } + + void setLastUsedTime(String packageName, long lastUsedTime) { + for (IntervalStats stats : mCurrentStats) { + stats.updateLastUsedTime(packageName, lastUsedTime); } notifyStatsChanged(); } @@ -390,6 +397,16 @@ class UserUsageStatsService { } } + long getLastUsedTime(String packageName) { + final IntervalStats yearly = mCurrentStats[UsageStatsManager.INTERVAL_YEARLY]; + UsageStats packageUsage; + if ((packageUsage = yearly.packageStats.get(packageName)) == null) { + return -1; + } else { + return packageUsage.getLastTimeUsed(); + } + } + void persistActiveStats() { if (mStatsChanged) { Slog.i(TAG, mLogPrefix + "Flushing usage stats to disk"); |