diff options
Diffstat (limited to 'services/java/com/android')
29 files changed, 630 insertions, 240 deletions
diff --git a/services/java/com/android/server/BatteryService.java b/services/java/com/android/server/BatteryService.java index fe8529b..0b4871d 100644 --- a/services/java/com/android/server/BatteryService.java +++ b/services/java/com/android/server/BatteryService.java @@ -463,10 +463,10 @@ public class BatteryService extends Binder { private final void logOutlier(long duration) { ContentResolver cr = mContext.getContentResolver(); - String dischargeThresholdString = Settings.Secure.getString(cr, - Settings.Secure.BATTERY_DISCHARGE_THRESHOLD); - String durationThresholdString = Settings.Secure.getString(cr, - Settings.Secure.BATTERY_DISCHARGE_DURATION_THRESHOLD); + String dischargeThresholdString = Settings.Global.getString(cr, + Settings.Global.BATTERY_DISCHARGE_THRESHOLD); + String durationThresholdString = Settings.Global.getString(cr, + Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD); if (dischargeThresholdString != null && durationThresholdString != null) { try { diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 891cac7..033aa1e 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -378,8 +378,8 @@ public class ConnectivityService extends IConnectivityManager.Stub { } // read our default dns server ip - String dns = Settings.Secure.getString(context.getContentResolver(), - Settings.Secure.DEFAULT_DNS_SERVER); + String dns = Settings.Global.getString(context.getContentResolver(), + Settings.Global.DEFAULT_DNS_SERVER); if (dns == null || dns.length() == 0) { dns = context.getResources().getString( com.android.internal.R.string.config_default_dns_server); @@ -715,9 +715,9 @@ public class ConnectivityService extends IConnectivityManager.Stub { /** Check system properties for the default value then use secure settings value, if any. */ int defaultDelay = SystemProperties.getInt( - "conn." + Settings.Secure.CONNECTIVITY_CHANGE_DELAY, - Settings.Secure.CONNECTIVITY_CHANGE_DELAY_DEFAULT); - return Settings.Secure.getInt(cr, Settings.Secure.CONNECTIVITY_CHANGE_DELAY, + "conn." + Settings.Global.CONNECTIVITY_CHANGE_DELAY, + ConnectivityManager.CONNECTIVITY_CHANGE_DELAY_DEFAULT); + return Settings.Global.getInt(cr, Settings.Global.CONNECTIVITY_CHANGE_DELAY, defaultDelay); } @@ -2997,11 +2997,11 @@ public class ConnectivityService extends IConnectivityManager.Stub { if (VDBG) log("handleInetConditionChange: starting a change hold"); // setup a new hold to debounce this if (mDefaultInetCondition > 50) { - delay = Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.INET_CONDITION_DEBOUNCE_UP_DELAY, 500); + delay = Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY, 500); } else { - delay = Settings.Secure.getInt(mContext.getContentResolver(), - Settings.Secure.INET_CONDITION_DEBOUNCE_DOWN_DELAY, 3000); + delay = Settings.Global.getInt(mContext.getContentResolver(), + Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY, 3000); } mInetConditionChangeInFlight = true; mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_INET_CONDITION_HOLD_END, @@ -3070,9 +3070,9 @@ public class ConnectivityService extends IConnectivityManager.Stub { mGlobalProxy = null; } ContentResolver res = mContext.getContentResolver(); - Settings.Secure.putString(res, Settings.Secure.GLOBAL_HTTP_PROXY_HOST, host); - Settings.Secure.putInt(res, Settings.Secure.GLOBAL_HTTP_PROXY_PORT, port); - Settings.Secure.putString(res, Settings.Secure.GLOBAL_HTTP_PROXY_EXCLUSION_LIST, + Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, host); + Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, port); + Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST, exclList); } @@ -3084,10 +3084,10 @@ public class ConnectivityService extends IConnectivityManager.Stub { private void loadGlobalProxy() { ContentResolver res = mContext.getContentResolver(); - String host = Settings.Secure.getString(res, Settings.Secure.GLOBAL_HTTP_PROXY_HOST); - int port = Settings.Secure.getInt(res, Settings.Secure.GLOBAL_HTTP_PROXY_PORT, 0); - String exclList = Settings.Secure.getString(res, - Settings.Secure.GLOBAL_HTTP_PROXY_EXCLUSION_LIST); + String host = Settings.Global.getString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST); + int port = Settings.Global.getInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, 0); + String exclList = Settings.Global.getString(res, + Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST); if (!TextUtils.isEmpty(host)) { ProxyProperties proxyProperties = new ProxyProperties(host, port, exclList); synchronized (mGlobalProxyLock) { @@ -3118,8 +3118,8 @@ public class ConnectivityService extends IConnectivityManager.Stub { } private void handleDeprecatedGlobalHttpProxy() { - String proxy = Settings.Secure.getString(mContext.getContentResolver(), - Settings.Secure.HTTP_PROXY); + String proxy = Settings.Global.getString(mContext.getContentResolver(), + Settings.Global.HTTP_PROXY); if (!TextUtils.isEmpty(proxy)) { String data[] = proxy.split(":"); String proxyHost = data[0]; @@ -3162,8 +3162,8 @@ public class ConnectivityService extends IConnectivityManager.Stub { void observe(Context context) { ContentResolver resolver = context.getContentResolver(); - resolver.registerContentObserver(Settings.Secure.getUriFor( - Settings.Secure.HTTP_PROXY), false, this); + resolver.registerContentObserver(Settings.Global.getUriFor( + Settings.Global.HTTP_PROXY), false, this); } @Override diff --git a/services/java/com/android/server/DevicePolicyManagerService.java b/services/java/com/android/server/DevicePolicyManagerService.java index 83fa55b..9607624 100644 --- a/services/java/com/android/server/DevicePolicyManagerService.java +++ b/services/java/com/android/server/DevicePolicyManagerService.java @@ -2124,9 +2124,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } exclusionList = exclusionList.trim(); ContentResolver res = mContext.getContentResolver(); - Settings.Secure.putString(res, Settings.Secure.GLOBAL_HTTP_PROXY_HOST, data[0]); - Settings.Secure.putInt(res, Settings.Secure.GLOBAL_HTTP_PROXY_PORT, proxyPort); - Settings.Secure.putString(res, Settings.Secure.GLOBAL_HTTP_PROXY_EXCLUSION_LIST, + Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_HOST, data[0]); + Settings.Global.putInt(res, Settings.Global.GLOBAL_HTTP_PROXY_PORT, proxyPort); + Settings.Global.putString(res, Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST, exclusionList); } diff --git a/services/java/com/android/server/DeviceStorageMonitorService.java b/services/java/com/android/server/DeviceStorageMonitorService.java index 750a2fb..a4c376d 100644 --- a/services/java/com/android/server/DeviceStorageMonitorService.java +++ b/services/java/com/android/server/DeviceStorageMonitorService.java @@ -163,8 +163,8 @@ public class DeviceStorageMonitorService extends Binder { mFreeMem = Long.parseLong(debugFreeMem); } // Read the log interval from secure settings - long freeMemLogInterval = Settings.Secure.getLong(mContentResolver, - Settings.Secure.SYS_FREE_STORAGE_LOG_INTERVAL, + long freeMemLogInterval = Settings.Global.getLong(mContentResolver, + Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL, DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES)*60*1000; //log the amount of free memory in event log long currTime = SystemClock.elapsedRealtime(); @@ -190,8 +190,8 @@ public class DeviceStorageMonitorService extends Binder { mFreeMem, mFreeSystem, mFreeCache); } // Read the reporting threshold from secure settings - long threshold = Settings.Secure.getLong(mContentResolver, - Settings.Secure.DISK_FREE_CHANGE_REPORTING_THRESHOLD, + long threshold = Settings.Global.getLong(mContentResolver, + Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD, DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD); // If mFree changed significantly log the new value long delta = mFreeMem - mLastReportedFreeMem; @@ -309,15 +309,15 @@ public class DeviceStorageMonitorService extends Binder { * any way */ private long getMemThreshold() { - long value = Settings.Secure.getInt( + long value = Settings.Global.getInt( mContentResolver, - Settings.Secure.SYS_STORAGE_THRESHOLD_PERCENTAGE, + Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE, DEFAULT_THRESHOLD_PERCENTAGE); if(localLOGV) Slog.v(TAG, "Threshold Percentage="+value); value = (value*mTotalMemory)/100; - long maxValue = Settings.Secure.getInt( + long maxValue = Settings.Global.getInt( mContentResolver, - Settings.Secure.SYS_STORAGE_THRESHOLD_MAX_BYTES, + Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES, DEFAULT_THRESHOLD_MAX_BYTES); //evaluate threshold value return value < maxValue ? value : maxValue; @@ -329,9 +329,9 @@ public class DeviceStorageMonitorService extends Binder { * any way */ private int getMemFullThreshold() { - int value = Settings.Secure.getInt( + int value = Settings.Global.getInt( mContentResolver, - Settings.Secure.SYS_STORAGE_FULL_THRESHOLD_BYTES, + Settings.Global.SYS_STORAGE_FULL_THRESHOLD_BYTES, DEFAULT_FULL_THRESHOLD_BYTES); if(localLOGV) Slog.v(TAG, "Full Threshold Bytes="+value); return value; diff --git a/services/java/com/android/server/DropBoxManagerService.java b/services/java/com/android/server/DropBoxManagerService.java index 0b12410..5008270 100644 --- a/services/java/com/android/server/DropBoxManagerService.java +++ b/services/java/com/android/server/DropBoxManagerService.java @@ -146,7 +146,7 @@ public final class DropBoxManagerService extends IDropBoxManagerService.Stub { context.registerReceiver(mReceiver, filter); mContentResolver.registerContentObserver( - Settings.Secure.CONTENT_URI, true, + Settings.Global.CONTENT_URI, true, new ContentObserver(new Handler()) { @Override public void onChange(boolean selfChange) { @@ -265,8 +265,8 @@ public final class DropBoxManagerService extends IDropBoxManagerService.Stub { } public boolean isTagEnabled(String tag) { - return !"disabled".equals(Settings.Secure.getString( - mContentResolver, Settings.Secure.DROPBOX_TAG_PREFIX + tag)); + return !"disabled".equals(Settings.Global.getString( + mContentResolver, Settings.Global.DROPBOX_TAG_PREFIX + tag)); } public synchronized DropBoxManager.Entry getNextEntry(String tag, long millis) { @@ -688,10 +688,10 @@ public final class DropBoxManagerService extends IDropBoxManagerService.Stub { private synchronized long trimToFit() { // Expunge aged items (including tombstones marking deleted data). - int ageSeconds = Settings.Secure.getInt(mContentResolver, - Settings.Secure.DROPBOX_AGE_SECONDS, DEFAULT_AGE_SECONDS); - int maxFiles = Settings.Secure.getInt(mContentResolver, - Settings.Secure.DROPBOX_MAX_FILES, DEFAULT_MAX_FILES); + int ageSeconds = Settings.Global.getInt(mContentResolver, + Settings.Global.DROPBOX_AGE_SECONDS, DEFAULT_AGE_SECONDS); + int maxFiles = Settings.Global.getInt(mContentResolver, + Settings.Global.DROPBOX_MAX_FILES, DEFAULT_MAX_FILES); long cutoffMillis = System.currentTimeMillis() - ageSeconds * 1000; while (!mAllFiles.contents.isEmpty()) { EntryFile entry = mAllFiles.contents.first(); @@ -710,12 +710,12 @@ public final class DropBoxManagerService extends IDropBoxManagerService.Stub { long uptimeMillis = SystemClock.uptimeMillis(); if (uptimeMillis > mCachedQuotaUptimeMillis + QUOTA_RESCAN_MILLIS) { - int quotaPercent = Settings.Secure.getInt(mContentResolver, - Settings.Secure.DROPBOX_QUOTA_PERCENT, DEFAULT_QUOTA_PERCENT); - int reservePercent = Settings.Secure.getInt(mContentResolver, - Settings.Secure.DROPBOX_RESERVE_PERCENT, DEFAULT_RESERVE_PERCENT); - int quotaKb = Settings.Secure.getInt(mContentResolver, - Settings.Secure.DROPBOX_QUOTA_KB, DEFAULT_QUOTA_KB); + int quotaPercent = Settings.Global.getInt(mContentResolver, + Settings.Global.DROPBOX_QUOTA_PERCENT, DEFAULT_QUOTA_PERCENT); + int reservePercent = Settings.Global.getInt(mContentResolver, + Settings.Global.DROPBOX_RESERVE_PERCENT, DEFAULT_RESERVE_PERCENT); + int quotaKb = Settings.Global.getInt(mContentResolver, + Settings.Global.DROPBOX_QUOTA_KB, DEFAULT_QUOTA_KB); mStatFs.restat(mDropBoxDir.getPath()); int available = mStatFs.getAvailableBlocks(); diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java index 6952d72..ec58e43 100644 --- a/services/java/com/android/server/InputMethodManagerService.java +++ b/services/java/com/android/server/InputMethodManagerService.java @@ -171,8 +171,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub final SettingsObserver mSettingsObserver; final IWindowManager mIWindowManager; final HandlerCaller mCaller; - private final InputMethodFileManager mFileManager; - private final InputMethodAndSubtypeListManager mImListManager; + private InputMethodFileManager mFileManager; + private InputMethodAndSubtypeListManager mImListManager; private final HardKeyboardListener mHardKeyboardListener; private final WindowManagerService mWindowManagerService; @@ -625,11 +625,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mShowOngoingImeSwitcherForPhones = false; - synchronized (mMethodMap) { - mFileManager = new InputMethodFileManager(mMethodMap); - } - mImListManager = new InputMethodAndSubtypeListManager(context, this); - final IntentFilter broadcastFilter = new IntentFilter(); broadcastFilter.addAction(Intent.ACTION_SCREEN_ON); broadcastFilter.addAction(Intent.ACTION_SCREEN_OFF); @@ -643,7 +638,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub new IUserSwitchObserver.Stub() { @Override public void onUserSwitching(int newUserId, IRemoteCallback reply) { - switchUser(newUserId); + synchronized(mMethodMap) { + switchUserLocked(newUserId); + } if (reply != null) { try { reply.sendResult(null); @@ -665,6 +662,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub // mSettings should be created before buildInputMethodListLocked mSettings = new InputMethodSettings( mRes, context.getContentResolver(), mMethodMap, mMethodList, userId); + mFileManager = new InputMethodFileManager(mMethodMap, userId); + mImListManager = new InputMethodAndSubtypeListManager(context, this); // Just checking if defaultImiId is empty or not final String defaultImiId = mSettings.getSelectedInputMethod(); @@ -736,6 +735,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub if (DEBUG) { Slog.i(TAG, "Locale has been changed to " + newLocale); } + // InputMethodAndSubtypeListManager should be reset when the locale is changed. + mImListManager = new InputMethodAndSubtypeListManager(mContext, this); buildInputMethodListLocked(mMethodList, mMethodMap); if (!updateOnlyWhenLocaleChanged) { final String selectedImiId = mSettings.getSelectedInputMethod(); @@ -744,6 +745,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub // set the current ime to the proper one. resetDefaultImeLocked(mContext); } + } else { + // If the locale is changed, needs to reset the default ime + resetDefaultImeLocked(mContext); } updateFromSettingsLocked(); mLastSystemLocale = newLocale; @@ -761,8 +765,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub resetAllInternalStateLocked(true); } - private void switchUser(int newUserId) { + private void switchUserLocked(int newUserId) { mSettings.setCurrentUserId(newUserId); + // InputMethodFileManager should be reset when the user is changed + mFileManager = new InputMethodFileManager(mMethodMap, newUserId); resetAllInternalStateLocked(false); } @@ -3816,6 +3822,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } + // TODO: Cache the state for each user and reset when the cached user is removed. private static class InputMethodFileManager { private static final String SYSTEM_PATH = "system"; private static final String INPUT_METHOD_PATH = "inputmethod"; @@ -3834,12 +3841,14 @@ public class InputMethodManagerService extends IInputMethodManager.Stub private final HashMap<String, InputMethodInfo> mMethodMap; private final HashMap<String, List<InputMethodSubtype>> mAdditionalSubtypesMap = new HashMap<String, List<InputMethodSubtype>>(); - public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap) { + public InputMethodFileManager(HashMap<String, InputMethodInfo> methodMap, int userId) { if (methodMap == null) { throw new NullPointerException("methodMap is null"); } mMethodMap = methodMap; - final File systemDir = new File(Environment.getDataDirectory(), SYSTEM_PATH); + final File systemDir = userId == UserHandle.USER_OWNER + ? new File(Environment.getDataDirectory(), SYSTEM_PATH) + : Environment.getUserSystemDirectory(userId); final File inputMethodDir = new File(systemDir, INPUT_METHOD_PATH); if (!inputMethodDir.mkdirs()) { Slog.w(TAG, "Couldn't create dir.: " + inputMethodDir.getAbsolutePath()); diff --git a/services/java/com/android/server/NsdService.java b/services/java/com/android/server/NsdService.java index 2a7a2eb..1b9742c 100644 --- a/services/java/com/android/server/NsdService.java +++ b/services/java/com/android/server/NsdService.java @@ -131,7 +131,7 @@ public class NsdService extends INsdManager.Stub { }; mContext.getContentResolver().registerContentObserver( - Settings.Secure.getUriFor(Settings.Secure.NSD_ON), + Settings.Global.getUriFor(Settings.Global.NSD_ON), false, contentObserver); } @@ -433,7 +433,7 @@ public class NsdService extends INsdManager.Stub { public void setEnabled(boolean enable) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL, "NsdService"); - Settings.Secure.putInt(mContentResolver, Settings.Secure.NSD_ON, enable ? 1 : 0); + Settings.Global.putInt(mContentResolver, Settings.Global.NSD_ON, enable ? 1 : 0); if (enable) { mNsdStateMachine.sendMessage(NsdManager.ENABLE); } else { @@ -453,7 +453,7 @@ public class NsdService extends INsdManager.Stub { } private boolean isNsdEnabled() { - boolean ret = Settings.Secure.getInt(mContentResolver, Settings.Secure.NSD_ON, 1) == 1; + boolean ret = Settings.Global.getInt(mContentResolver, Settings.Global.NSD_ON, 1) == 1; if (DBG) Slog.d(TAG, "Network service discovery enabled " + ret); return ret; } diff --git a/services/java/com/android/server/StatusBarManagerService.java b/services/java/com/android/server/StatusBarManagerService.java index b567992..87b0eb3 100644 --- a/services/java/com/android/server/StatusBarManagerService.java +++ b/services/java/com/android/server/StatusBarManagerService.java @@ -117,45 +117,34 @@ public class StatusBarManagerService extends IStatusBarService.Stub // ================================================================================ // From IStatusBarService // ================================================================================ - public void expandNotifications() { + public void expandNotificationsPanel() { enforceExpandStatusBar(); if (mBar != null) { try { - mBar.animateExpandNotifications(); + mBar.animateExpandNotificationsPanel(); } catch (RemoteException ex) { } } } - public void collapseNotifications() { + public void collapsePanels() { enforceExpandStatusBar(); if (mBar != null) { try { - mBar.animateCollapseNotifications(); + mBar.animateCollapsePanels(); } catch (RemoteException ex) { } } } - public void expandQuickSettings() { + public void expandSettingsPanel() { enforceExpandStatusBar(); if (mBar != null) { try { - mBar.animateExpandQuickSettings(); - } catch (RemoteException ex) { - } - } - } - - public void collapseQuickSettings() { - enforceExpandStatusBar(); - - if (mBar != null) { - try { - mBar.animateCollapseQuickSettings(); + mBar.animateExpandSettingsPanel(); } catch (RemoteException ex) { } } @@ -620,8 +609,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub String action = intent.getAction(); if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action) || Intent.ACTION_SCREEN_OFF.equals(action)) { - collapseNotifications(); - collapseQuickSettings(); + collapsePanels(); } /* else if (Telephony.Intents.SPN_STRINGS_UPDATED_ACTION.equals(action)) { diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java index 738e19b..b684c90 100644 --- a/services/java/com/android/server/SystemServer.java +++ b/services/java/com/android/server/SystemServer.java @@ -38,7 +38,7 @@ import android.os.StrictMode; import android.os.SystemClock; import android.os.SystemProperties; import android.server.search.SearchManagerService; -import android.service.dreams.Dream; +import android.service.dreams.DreamService; import android.util.DisplayMetrics; import android.util.EventLog; import android.util.Log; @@ -741,7 +741,7 @@ class ServerThread extends Thread { Slog.i(TAG, "Dreams Service"); // Dreams (interactive idle-time views, a/k/a screen savers) dreamy = new DreamManagerService(context, wmHandler); - ServiceManager.addService(Dream.DREAM_SERVICE, dreamy); + ServiceManager.addService(DreamService.DREAM_SERVICE, dreamy); } catch (Throwable e) { reportWtf("starting DreamManagerService", e); } diff --git a/services/java/com/android/server/UiModeManagerService.java b/services/java/com/android/server/UiModeManagerService.java index 3b8caba..d1af2b0 100644 --- a/services/java/com/android/server/UiModeManagerService.java +++ b/services/java/com/android/server/UiModeManagerService.java @@ -39,7 +39,7 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.os.UserHandle; import android.provider.Settings; -import android.service.dreams.Dream; +import android.service.dreams.DreamService; import android.service.dreams.IDreamManager; import android.util.Slog; @@ -501,7 +501,7 @@ class UiModeManagerService extends IUiModeManager.Stub { Slog.i(TAG, "Activating dream while docked."); try { IDreamManager dreamManagerService = IDreamManager.Stub.asInterface( - ServiceManager.getService(Dream.DREAM_SERVICE)); + ServiceManager.getService(DreamService.DREAM_SERVICE)); dreamManagerService.dream(); } catch (RemoteException ex) { Slog.e(TAG, "Could not start dream when docked.", ex); diff --git a/services/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/java/com/android/server/accessibility/AccessibilityManagerService.java index 25f98de..2f57eb0 100644 --- a/services/java/com/android/server/accessibility/AccessibilityManagerService.java +++ b/services/java/com/android/server/accessibility/AccessibilityManagerService.java @@ -56,6 +56,7 @@ import android.os.RemoteException; import android.os.ServiceManager; import android.os.SystemClock; import android.os.UserHandle; +import android.os.UserManager; import android.provider.Settings; import android.text.TextUtils; import android.text.TextUtils.SimpleStringSplitter; @@ -108,9 +109,16 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { private static final String LOG_TAG = "AccessibilityManagerService"; + // TODO: This is arbitrary. When there is time implement this by watching + // when that accessibility services are bound. + private static final int WAIT_FOR_USER_STATE_FULLY_INITIALIZED_MILLIS = 5000; + private static final String FUNCTION_REGISTER_UI_TEST_AUTOMATION_SERVICE = "registerUiTestAutomationService"; + private static final String TEMPORARY_ENABLE_ACCESSIBILITY_UNTIL_KEYGUARD_REMOVED = + "temporaryEnableAccessibilityStateUntilKeyguardRemoved"; + private static final char COMPONENT_NAME_SEPARATOR = ':'; private static final int OWN_PROCESS_ID = android.os.Process.myPid(); @@ -157,6 +165,9 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { private final SparseArray<UserState> mUserStates = new SparseArray<UserState>(); + private final TempUserStateChangeMemento mTempStateChangeForCurrentUserMemento = + new TempUserStateChangeMemento(); + private int mCurrentUserId = UserHandle.USER_OWNER; private UserState getCurrentUserStateLocked() { @@ -268,12 +279,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { // package changes monitor.register(mContext, null, UserHandle.ALL, true); - // user change - IntentFilter userFilter = new IntentFilter(); - userFilter.addAction(Intent.ACTION_USER_SWITCHED); - userFilter.addAction(Intent.ACTION_USER_REMOVED); + // user change and unlock + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(Intent.ACTION_USER_SWITCHED); + intentFilter.addAction(Intent.ACTION_USER_REMOVED); + intentFilter.addAction(Intent.ACTION_USER_PRESENT); - mContext.registerReceiver(new BroadcastReceiver() { + mContext.registerReceiverAsUser(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); @@ -281,9 +293,11 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { switchUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0)); } else if (Intent.ACTION_USER_REMOVED.equals(action)) { removeUser(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0)); + } else if (Intent.ACTION_USER_PRESENT.equals(action)) { + restoreStateFromMementoIfNeeded(); } } - }, userFilter); + }, UserHandle.ALL, intentFilter, null, null); } public int addClient(IAccessibilityManagerClient client, int userId) { @@ -510,6 +524,37 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } } + public void temporaryEnableAccessibilityStateUntilKeyguardRemoved( + ComponentName service, boolean touchExplorationEnabled) { + mSecurityPolicy.enforceCallingPermission( + Manifest.permission.TEMPORARY_ENABLE_ACCESSIBILITY, + TEMPORARY_ENABLE_ACCESSIBILITY_UNTIL_KEYGUARD_REMOVED); + try { + if (!mWindowManagerService.isKeyguardLocked()) { + return; + } + } catch (RemoteException re) { + return; + } + synchronized (mLock) { + UserState userState = getCurrentUserStateLocked(); + // Stash the old state so we can restore it when the keyguard is gone. + mTempStateChangeForCurrentUserMemento.initialize(mCurrentUserId, getCurrentUserStateLocked()); + // Set the temporary state. + userState.mIsAccessibilityEnabled = true; + userState.mIsTouchExplorationEnabled= touchExplorationEnabled; + userState.mIsDisplayMagnificationEnabled = false; + userState.mEnabledServices.clear(); + userState.mEnabledServices.add(service); + userState.mTouchExplorationGrantedServices.clear(); + userState.mTouchExplorationGrantedServices.add(service); + // Update the internal state. + performServiceManagementLocked(userState); + updateInputFilterLocked(userState); + scheduleSendStateToClientsLocked(userState); + } + } + public void unregisterUiTestAutomationService(IAccessibilityServiceClient serviceClient) { synchronized (mLock) { // Automation service is not bound, so pretend it died to perform clean up. @@ -600,9 +645,9 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { private void switchUser(int userId) { synchronized (mLock) { - if (userId == mCurrentUserId) { - return; - } + // The user switched so we do not need to restore the current user + // state since we will fully rebuild it when he becomes current again. + mTempStateChangeForCurrentUserMemento.clear(); // Disconnect from services for the old user. UserState oldUserState = getUserStateLocked(mCurrentUserId); @@ -620,6 +665,10 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { // Recreate the internal state for the new user. mMainHandler.obtainMessage(MainHandler.MSG_SEND_RECREATE_INTERNAL_STATE, mCurrentUserId, 0).sendToTarget(); + + // Schedule announcement of the current user if needed. + mMainHandler.sendEmptyMessageDelayed(MainHandler.MSG_ANNOUNCE_NEW_USER_IF_NEEDED, + WAIT_FOR_USER_STATE_FULLY_INITIALIZED_MILLIS); } } @@ -629,6 +678,21 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } } + private void restoreStateFromMementoIfNeeded() { + synchronized (mLock) { + if (mTempStateChangeForCurrentUserMemento.mUserId != UserHandle.USER_NULL) { + UserState userState = getCurrentUserStateLocked(); + // Restore the state from the memento. + mTempStateChangeForCurrentUserMemento.applyTo(userState); + mTempStateChangeForCurrentUserMemento.clear(); + // Update the internal state. + performServiceManagementLocked(userState); + updateInputFilterLocked(userState); + scheduleSendStateToClientsLocked(userState); + } + } + } + private Service getQueryBridge() { if (mQueryBridge == null) { AccessibilityServiceInfo info = new AccessibilityServiceInfo(); @@ -763,7 +827,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { private void tryAddServiceLocked(Service service, int userId) { try { UserState userState = getUserStateLocked(userId); - if (userState.mServices.contains(service) || !service.isConfigured()) { + if (userState.mServices.contains(service)) { return; } service.linkToOwnDeath(); @@ -812,7 +876,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { private boolean canDispathEventLocked(Service service, AccessibilityEvent event, int handledFeedbackTypes) { - if (!service.isConfigured()) { + if (!service.canReceiveEvents()) { return false; } @@ -1076,6 +1140,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { handleDisplayMagnificationEnabledSettingChangedLocked(userState); handleAccessibilityEnabledSettingChangedLocked(userState); + performServiceManagementLocked(userState); updateInputFilterLocked(userState); scheduleSendStateToClientsLocked(userState); } @@ -1084,6 +1149,9 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { userState.mIsAccessibilityEnabled = Settings.Secure.getIntForUser( mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0, userState.mUserId) == 1; + } + + private void performServiceManagementLocked(UserState userState) { if (userState.mIsAccessibilityEnabled ) { manageServicesLocked(userState); } else { @@ -1124,7 +1192,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { private void tryEnableTouchExplorationLocked(final Service service) { UserState userState = getUserStateLocked(service.mUserId); - if (!userState.mIsTouchExplorationEnabled && service.mRequestTouchExplorationMode) { + if (!userState.mIsTouchExplorationEnabled && service.mRequestTouchExplorationMode + && service.canReceiveEvents()) { final boolean canToggleTouchExploration = userState.mTouchExplorationGrantedServices.contains(service.mComponentName); if (!service.mIsAutomation && !canToggleTouchExploration) { @@ -1137,6 +1206,9 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } private void tryDisableTouchExplorationLocked(Service service) { + if (!service.canReceiveEvents()) { + return; + } UserState userState = getUserStateLocked(service.mUserId); if (userState.mIsTouchExplorationEnabled) { final int serviceCount = userState.mServices.size(); @@ -1186,6 +1258,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { public static final int MSG_SEND_CLEARED_STATE_TO_CLIENTS_FOR_USER = 3; public static final int MSG_SEND_RECREATE_INTERNAL_STATE = 4; public static final int MSG_UPDATE_ACTIVE_WINDOW = 5; + public static final int MSG_ANNOUNCE_NEW_USER_IF_NEEDED = 6; public MainHandler(Looper looper) { super(looper); @@ -1226,6 +1299,25 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { final int eventType = msg.arg2; mSecurityPolicy.updateActiveWindow(windowId, eventType); } break; + case MSG_ANNOUNCE_NEW_USER_IF_NEEDED: { + announceNewUserIfNeeded(); + } break; + } + } + + private void announceNewUserIfNeeded() { + synchronized (mLock) { + UserState userState = getCurrentUserStateLocked(); + if (userState.mIsAccessibilityEnabled) { + UserManager userManager = (UserManager) mContext.getSystemService( + Context.USER_SERVICE); + String message = mContext.getString(R.string.user_switched, + userManager.getUserInfo(mCurrentUserId).name); + AccessibilityEvent event = AccessibilityEvent.obtain( + AccessibilityEvent.TYPE_ANNOUNCEMENT); + event.getText().add(message); + sendAccessibilityEvent(event, mCurrentUserId); + } } } @@ -1376,7 +1468,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { // If this service is up and running we may have to enable touch // exploration, otherwise this will happen when the service connects. synchronized (mLock) { - if (isConfigured()) { + if (canReceiveEvents()) { if (mRequestTouchExplorationMode) { tryEnableTouchExplorationLocked(this); } else { @@ -1417,13 +1509,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { return false; } - /** - * Returns if the service is configured i.e. at least event types of interest - * and feedback type must be set. - * - * @return True if the service is configured, false otherwise. - */ - public boolean isConfigured() { + public boolean canReceiveEvents() { return (mEventTypes != 0 && mFeedbackType != 0 && mService != null); } @@ -1940,7 +2026,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { StatusBarManager statusBarManager = (StatusBarManager) mContext.getSystemService( android.app.Service.STATUS_BAR_SERVICE); - statusBarManager.expandNotifications(); + statusBarManager.expandNotificationsPanel(); Binder.restoreCallingIdentity(token); } @@ -1950,7 +2036,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { StatusBarManager statusBarManager = (StatusBarManager) mContext.getSystemService( android.app.Service.STATUS_BAR_SERVICE); - statusBarManager.expandQuickSettings(); + statusBarManager.expandSettingsPanel(); Binder.restoreCallingIdentity(token); } @@ -2229,6 +2315,46 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } } + private class TempUserStateChangeMemento { + public int mUserId = UserHandle.USER_NULL; + public boolean mIsAccessibilityEnabled; + public boolean mIsTouchExplorationEnabled; + public boolean mIsDisplayMagnificationEnabled; + public final Set<ComponentName> mEnabledServices = new HashSet<ComponentName>(); + public final Set<ComponentName> mTouchExplorationGrantedServices = + new HashSet<ComponentName>(); + + public void initialize(int userId, UserState userState) { + mUserId = userId; + mIsAccessibilityEnabled = userState.mIsAccessibilityEnabled; + mIsTouchExplorationEnabled = userState.mIsTouchExplorationEnabled; + mIsDisplayMagnificationEnabled = userState.mIsDisplayMagnificationEnabled; + mEnabledServices.clear(); + mEnabledServices.addAll(userState.mEnabledServices); + mTouchExplorationGrantedServices.clear(); + mTouchExplorationGrantedServices.addAll(userState.mTouchExplorationGrantedServices); + } + + public void applyTo(UserState userState) { + userState.mIsAccessibilityEnabled = mIsAccessibilityEnabled; + userState.mIsTouchExplorationEnabled = mIsTouchExplorationEnabled; + userState.mIsDisplayMagnificationEnabled = mIsDisplayMagnificationEnabled; + userState.mEnabledServices.clear(); + userState.mEnabledServices.addAll(mEnabledServices); + userState.mTouchExplorationGrantedServices.clear(); + userState.mTouchExplorationGrantedServices.addAll(mTouchExplorationGrantedServices); + } + + public void clear() { + mUserId = UserHandle.USER_NULL; + mIsAccessibilityEnabled = false; + mIsTouchExplorationEnabled = false; + mIsDisplayMagnificationEnabled = false; + mEnabledServices.clear(); + mTouchExplorationGrantedServices.clear(); + } + } + private final class AccessibilityContentObserver extends ContentObserver { private final Uri mAccessibilityEnabledUri = Settings.Secure.getUriFor( @@ -2272,6 +2398,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { if (mUiAutomationService == null) { UserState userState = getCurrentUserStateLocked(); handleAccessibilityEnabledSettingChangedLocked(userState); + performServiceManagementLocked(userState); updateInputFilterLocked(userState); scheduleSendStateToClientsLocked(userState); } diff --git a/services/java/com/android/server/accessibility/TouchExplorer.java b/services/java/com/android/server/accessibility/TouchExplorer.java index 921bed7..6e57d1f 100644 --- a/services/java/com/android/server/accessibility/TouchExplorer.java +++ b/services/java/com/android/server/accessibility/TouchExplorer.java @@ -102,6 +102,10 @@ class TouchExplorer implements EventStreamTransformation { // The timeout after which we are no longer trying to detect a gesture. private static final int EXIT_GESTURE_DETECTION_TIMEOUT = 2000; + // The timeout to send interaction end events in case we did not + // receive the expected hover exit event due to a misbehaving app. + private static final int SEND_INTERACTION_END_EVENTS_TIMEOUT = 200; + // Temporary array for storing pointer IDs. private final int[] mTempPointerIds = new int[MAX_POINTER_COUNT]; @@ -135,6 +139,9 @@ class TouchExplorer implements EventStreamTransformation { // Command for delayed sending of a hover exit event. private final SendHoverDelayed mSendHoverExitDelayed; + // Command for delayed sending of interaction ending events. + private final SendInteractionEndEventsDelayed mSendInteractionEndEventsDelayed; + // Command for delayed sending of a long press. private final PerformLongPressDelayed mPerformLongPressDelayed; @@ -233,6 +240,7 @@ class TouchExplorer implements EventStreamTransformation { mGestureLibrary.load(); mSendHoverEnterDelayed = new SendHoverDelayed(MotionEvent.ACTION_HOVER_ENTER, true); mSendHoverExitDelayed = new SendHoverDelayed(MotionEvent.ACTION_HOVER_EXIT, false); + mSendInteractionEndEventsDelayed = new SendInteractionEndEventsDelayed(); mDoubleTapDetector = new DoubleTapDetector(); final float density = context.getResources().getDisplayMetrics().density; mScaledMinPointerDistanceToUseMiddleLocation = @@ -278,6 +286,7 @@ class TouchExplorer implements EventStreamTransformation { mSendHoverExitDelayed.remove(); mPerformLongPressDelayed.remove(); mExitGestureDetectionModeDelayed.remove(); + mSendInteractionEndEventsDelayed.remove(); // Reset the pointer trackers. mReceivedPointerTracker.clear(); mInjectedPointerTracker.clear(); @@ -334,6 +343,7 @@ class TouchExplorer implements EventStreamTransformation { // last hover exit event. if (mTouchExplorationGestureEnded && eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) { + mSendInteractionEndEventsDelayed.remove(); mTouchExplorationGestureEnded = false; sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END); } @@ -342,6 +352,7 @@ class TouchExplorer implements EventStreamTransformation { // last hover exit and the touch exploration gesture end events. if (mTouchInteractionEnded && eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) { + mSendInteractionEndEventsDelayed.remove(); mTouchInteractionEnded = false; sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END); } @@ -416,6 +427,10 @@ class TouchExplorer implements EventStreamTransformation { mSendHoverExitDelayed.remove(); } + if (mSendInteractionEndEventsDelayed.isPending()) { + mSendInteractionEndEventsDelayed.forceSendAndRemove(); + } + mPerformLongPressDelayed.remove(); // If we have the first tap schedule a long press and break @@ -685,13 +700,6 @@ class TouchExplorer implements EventStreamTransformation { } } } break; - case MotionEvent.ACTION_POINTER_UP: { - final int pointerId = event.getPointerId(event.getActionIndex()); - if (mReceivedPointerTracker.isActiveOrWasLastActiveUpPointer(pointerId)) { - sendUpForInjectedDownPointers(event, policyFlags); - mCurrentState = STATE_TOUCH_EXPLORING; - } - } break; case MotionEvent.ACTION_UP: { // Announce the end of a new touch interaction. sendAccessibilityEvent( @@ -873,6 +881,9 @@ class TouchExplorer implements EventStreamTransformation { final int pointerIdBits = event.getPointerIdBits(); mTouchExplorationGestureEnded = true; mTouchInteractionEnded = true; + if (!mSendInteractionEndEventsDelayed.isPending()) { + mSendInteractionEndEventsDelayed.post(); + } sendMotionEvent(event, MotionEvent.ACTION_HOVER_EXIT, pointerIdBits, policyFlags); } } @@ -1300,6 +1311,11 @@ class TouchExplorer implements EventStreamTransformation { @Override public void run() { + // Announce the end of gesture recognition. + sendAccessibilityEvent(AccessibilityEvent.TYPE_GESTURE_DETECTION_END); + // Clearing puts is in touch exploration state with a finger already + // down, so announce the transition to exploration state. + sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START); clear(); } } @@ -1479,10 +1495,16 @@ class TouchExplorer implements EventStreamTransformation { } else { mTouchExplorationGestureEnded = true; mTouchInteractionEnded = true; + if (!mSendInteractionEndEventsDelayed.isPending()) { + mSendInteractionEndEventsDelayed.post(); + } } } else { if (!mGestureStarted) { mTouchInteractionEnded = true; + if (!mSendInteractionEndEventsDelayed.isPending()) { + mSendInteractionEndEventsDelayed.post(); + } } } sendMotionEvent(mPrototype, mHoverAction, mPointerIdBits, mPolicyFlags); @@ -1490,6 +1512,40 @@ class TouchExplorer implements EventStreamTransformation { } } + private class SendInteractionEndEventsDelayed implements Runnable { + + public void remove() { + mHandler.removeCallbacks(this); + } + + public void post() { + mHandler.postDelayed(this, SEND_INTERACTION_END_EVENTS_TIMEOUT); + } + + public boolean isPending() { + return mHandler.hasCallbacks(this); + } + + public void forceSendAndRemove() { + if (isPending()) { + run(); + remove(); + } + } + + @Override + public void run() { + if (mTouchExplorationGestureEnded) { + mTouchExplorationGestureEnded = false; + sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END); + } + if (mTouchInteractionEnded) { + mTouchInteractionEnded = false; + sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END); + } + } + } + @Override public String toString() { return LOG_TAG; diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 0221245..3428326 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -912,21 +912,38 @@ public final class ActivityManagerService extends ActivityManagerNative switch (msg.what) { case SHOW_ERROR_MSG: { HashMap data = (HashMap) msg.obj; + boolean showBackground = Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0; synchronized (ActivityManagerService.this) { ProcessRecord proc = (ProcessRecord)data.get("app"); + AppErrorResult res = (AppErrorResult) data.get("result"); if (proc != null && proc.crashDialog != null) { Slog.e(TAG, "App already has crash dialog: " + proc); + if (res != null) { + res.set(0); + } + return; + } + if (!showBackground && UserHandle.getAppId(proc.uid) + >= Process.FIRST_APPLICATION_UID && proc.userId != mCurrentUserId + && proc.pid != MY_PID) { + Slog.w(TAG, "Skipping crash dialog of " + proc + ": background"); + if (res != null) { + res.set(0); + } return; } - AppErrorResult res = (AppErrorResult) data.get("result"); if (mShowDialogs && !mSleeping && !mShuttingDown) { - Dialog d = new AppErrorDialog(mContext, res, proc); + Dialog d = new AppErrorDialog(mContext, + ActivityManagerService.this, res, proc); d.show(); proc.crashDialog = d; } else { // The device is asleep, so just pretend that the user // saw a crash dialog and hit "force quit". - res.set(0); + if (res != null) { + res.set(0); + } } } @@ -977,7 +994,8 @@ public final class ActivityManagerService extends ActivityManagerNative } AppErrorResult res = (AppErrorResult) data.get("result"); if (mShowDialogs && !mSleeping && !mShuttingDown) { - Dialog d = new StrictModeViolationDialog(mContext, res, proc); + Dialog d = new StrictModeViolationDialog(mContext, + ActivityManagerService.this, res, proc); d.show(); proc.crashDialog = d; } else { @@ -3683,7 +3701,8 @@ public final class ActivityManagerService extends ActivityManagerNative void closeSystemDialogsLocked(String reason) { Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); - intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY + | Intent.FLAG_RECEIVER_FOREGROUND); if (reason != null) { intent.putExtra("reason", reason); } @@ -3755,7 +3774,8 @@ public final class ActivityManagerService extends ActivityManagerNative Intent intent = new Intent(Intent.ACTION_PACKAGE_RESTARTED, Uri.fromParts("package", packageName, null)); if (!mProcessesReady) { - intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY + | Intent.FLAG_RECEIVER_FOREGROUND); } intent.putExtra(Intent.EXTRA_UID, uid); intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(uid)); @@ -3768,7 +3788,8 @@ public final class ActivityManagerService extends ActivityManagerNative private void forceStopUserLocked(int userId) { forceStopPackageLocked(null, -1, false, false, true, false, userId); Intent intent = new Intent(Intent.ACTION_USER_STOPPED); - intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY + | Intent.FLAG_RECEIVER_FOREGROUND); intent.putExtra(Intent.EXTRA_USER_HANDLE, userId); broadcastIntentLocked(null, null, intent, null, null, 0, null, null, null, @@ -7363,7 +7384,14 @@ public final class ActivityManagerService extends ActivityManagerNative return mController != null; } } - + + public void requestBugReport() { + // No permission check because this can't do anything harmful -- + // it will just eventually cause the user to be presented with + // a UI to select where the bug report goes. + SystemProperties.set("ctl.start", "bugreport"); + } + public void registerProcessObserver(IProcessObserver observer) { enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER, "registerProcessObserver()"); @@ -7698,9 +7726,9 @@ public final class ActivityManagerService extends ActivityManagerNative } } intent.addFlags(Intent.FLAG_RECEIVER_BOOT_UPGRADE); - + ArrayList<ComponentName> lastDoneReceivers = readLastDonePreBootReceivers(); - + final ArrayList<ComponentName> doneReceivers = new ArrayList<ComponentName>(); for (int i=0; i<ris.size(); i++) { ActivityInfo ai = ris.get(i).activityInfo; @@ -7874,7 +7902,8 @@ public final class ActivityManagerService extends ActivityManagerNative long ident = Binder.clearCallingIdentity(); try { Intent intent = new Intent(Intent.ACTION_USER_STARTED); - intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY + | Intent.FLAG_RECEIVER_FOREGROUND); intent.putExtra(Intent.EXTRA_USER_HANDLE, mCurrentUserId); broadcastIntentLocked(null, null, intent, null, null, 0, null, null, null, @@ -8081,8 +8110,15 @@ public final class ActivityManagerService extends ActivityManagerNative } void startAppProblemLocked(ProcessRecord app) { - app.errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver( - mContext, app.info.packageName, app.info.flags); + if (app.userId == mCurrentUserId) { + app.errorReportReceiver = ApplicationErrorReport.getErrorReportReceiver( + mContext, app.info.packageName, app.info.flags); + } else { + // If this app is not running under the current user, then we + // can't give it a report button because that would require + // launching the report UI under a different user. + app.errorReportReceiver = null; + } skipCurrentReceiverLocked(app); } @@ -8464,8 +8500,8 @@ public final class ActivityManagerService extends ActivityManagerNative sb.append(crashInfo.stackTrace); } - String setting = Settings.Secure.ERROR_LOGCAT_PREFIX + dropboxTag; - int lines = Settings.Secure.getInt(mContext.getContentResolver(), setting, 0); + String setting = Settings.Global.ERROR_LOGCAT_PREFIX + dropboxTag; + int lines = Settings.Global.getInt(mContext.getContentResolver(), setting, 0); if (lines > 0) { sb.append("\n"); @@ -8590,7 +8626,7 @@ public final class ActivityManagerService extends ActivityManagerNative if (appErrorIntent != null) { try { - mContext.startActivity(appErrorIntent); + mContext.startActivityAsUser(appErrorIntent, new UserHandle(r.userId)); } catch (ActivityNotFoundException e) { Slog.w(TAG, "bug report receiver dissappeared", e); } @@ -11427,6 +11463,17 @@ public final class ActivityManagerService extends ActivityManagerNative for (int user : users) { List<ResolveInfo> newReceivers = AppGlobals.getPackageManager() .queryIntentReceivers(intent, resolvedType, STOCK_PM_FLAGS, user); + if (user != 0 && newReceivers != null) { + // If this is not the primary user, we need to check for + // any receivers that should be filtered out. + for (int i=0; i<newReceivers.size(); i++) { + ResolveInfo ri = newReceivers.get(i); + if ((ri.activityInfo.flags&ActivityInfo.FLAG_PRIMARY_USER_ONLY) != 0) { + newReceivers.remove(i); + i--; + } + } + } if (newReceivers != null && newReceivers.size() == 0) { newReceivers = null; } @@ -12271,12 +12318,14 @@ public final class ActivityManagerService extends ActivityManagerNative } Intent intent = new Intent(Intent.ACTION_CONFIGURATION_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY - | Intent.FLAG_RECEIVER_REPLACE_PENDING); + | Intent.FLAG_RECEIVER_REPLACE_PENDING + | Intent.FLAG_RECEIVER_FOREGROUND); broadcastIntentLocked(null, null, intent, null, null, 0, null, null, null, false, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL); if ((changes&ActivityInfo.CONFIG_LOCALE) != 0) { - broadcastIntentLocked(null, null, - new Intent(Intent.ACTION_LOCALE_CHANGED), + intent = new Intent(Intent.ACTION_LOCALE_CHANGED); + intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); + broadcastIntentLocked(null, null, intent, null, null, 0, null, null, null, false, false, MY_PID, Process.SYSTEM_UID, UserHandle.USER_ALL); } @@ -14057,6 +14106,7 @@ public final class ActivityManagerService extends ActivityManagerNative return false; } + mWindowManager.lockNow(); mWindowManager.startFreezingScreen(R.anim.screen_user_exit, R.anim.screen_user_enter); @@ -14084,7 +14134,8 @@ public final class ActivityManagerService extends ActivityManagerNative mHandler.sendMessageDelayed(mHandler.obtainMessage(USER_SWITCH_TIMEOUT_MSG, oldUserId, userId, uss), USER_SWITCH_TIMEOUT); Intent intent = new Intent(Intent.ACTION_USER_STARTED); - intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY + | Intent.FLAG_RECEIVER_FOREGROUND); intent.putExtra(Intent.EXTRA_USER_HANDLE, userId); broadcastIntentLocked(null, null, intent, null, null, 0, null, null, null, @@ -14093,17 +14144,17 @@ public final class ActivityManagerService extends ActivityManagerNative if ((userInfo.flags&UserInfo.FLAG_INITIALIZED) == 0) { if (userId != 0) { intent = new Intent(Intent.ACTION_USER_INITIALIZE); + intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); broadcastIntentLocked(null, null, intent, null, new IIntentReceiver.Stub() { public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) { - synchronized (ActivityManagerService.this) { - getUserManagerLocked().makeInitialized(userInfo.id); - } + userInitialized(uss); } }, 0, null, null, null, true, false, MY_PID, Process.SYSTEM_UID, userId); + uss.initializing = true; } else { getUserManagerLocked().makeInitialized(userInfo.id); } @@ -14130,7 +14181,8 @@ public final class ActivityManagerService extends ActivityManagerNative Intent intent; if (oldUserId >= 0) { intent = new Intent(Intent.ACTION_USER_BACKGROUND); - intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY + | Intent.FLAG_RECEIVER_FOREGROUND); intent.putExtra(Intent.EXTRA_USER_HANDLE, oldUserId); broadcastIntentLocked(null, null, intent, null, null, 0, null, null, null, @@ -14138,13 +14190,15 @@ public final class ActivityManagerService extends ActivityManagerNative } if (newUserId >= 0) { intent = new Intent(Intent.ACTION_USER_FOREGROUND); - intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY + | Intent.FLAG_RECEIVER_FOREGROUND); intent.putExtra(Intent.EXTRA_USER_HANDLE, newUserId); broadcastIntentLocked(null, null, intent, null, null, 0, null, null, null, false, false, MY_PID, Process.SYSTEM_UID, newUserId); intent = new Intent(Intent.ACTION_USER_SWITCHED); - intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY + | Intent.FLAG_RECEIVER_FOREGROUND); intent.putExtra(Intent.EXTRA_USER_HANDLE, newUserId); broadcastIntentLocked(null, null, intent, null, null, 0, null, null, @@ -14175,6 +14229,7 @@ public final class ActivityManagerService extends ActivityManagerNative } }; synchronized (this) { + uss.switching = true; mCurUserSwitchCallback = callback; } for (int i=0; i<N; i++) { @@ -14206,6 +14261,14 @@ public final class ActivityManagerService extends ActivityManagerNative oldUserId, newUserId, uss)); } + void userInitialized(UserStartedState uss) { + synchronized (ActivityManagerService.this) { + getUserManagerLocked().makeInitialized(uss.mHandle.getIdentifier()); + uss.initializing = false; + completeSwitchAndInitalizeLocked(uss); + } + } + void continueUserSwitch(UserStartedState uss, int oldUserId, int newUserId) { final int N = mUserSwitchObservers.beginBroadcast(); for (int i=0; i<N; i++) { @@ -14216,6 +14279,13 @@ public final class ActivityManagerService extends ActivityManagerNative } mUserSwitchObservers.finishBroadcast(); synchronized (this) { + uss.switching = false; + completeSwitchAndInitalizeLocked(uss); + } + } + + void completeSwitchAndInitalizeLocked(UserStartedState uss) { + if (!uss.switching && !uss.initializing) { mWindowManager.stopFreezingScreen(); } } diff --git a/services/java/com/android/server/am/AppErrorDialog.java b/services/java/com/android/server/am/AppErrorDialog.java index 57e11cf..0ebbe3b 100644 --- a/services/java/com/android/server/am/AppErrorDialog.java +++ b/services/java/com/android/server/am/AppErrorDialog.java @@ -29,6 +29,7 @@ import android.view.WindowManager; class AppErrorDialog extends BaseErrorDialog { private final static String TAG = "AppErrorDialog"; + private final ActivityManagerService mService; private final AppErrorResult mResult; private final ProcessRecord mProc; @@ -39,11 +40,13 @@ class AppErrorDialog extends BaseErrorDialog { // 5-minute timeout, then we automatically dismiss the crash dialog static final long DISMISS_TIMEOUT = 1000 * 60 * 5; - public AppErrorDialog(Context context, AppErrorResult result, ProcessRecord app) { + public AppErrorDialog(Context context, ActivityManagerService service, + AppErrorResult result, ProcessRecord app) { super(context); Resources res = context.getResources(); + mService = service; mProc = app; mResult = result; CharSequence name; @@ -86,7 +89,7 @@ class AppErrorDialog extends BaseErrorDialog { private final Handler mHandler = new Handler() { public void handleMessage(Message msg) { - synchronized (mProc) { + synchronized (mService) { if (mProc != null && mProc.crashDialog == AppErrorDialog.this) { mProc.crashDialog = null; } diff --git a/services/java/com/android/server/am/StrictModeViolationDialog.java b/services/java/com/android/server/am/StrictModeViolationDialog.java index fe76d18..35d50a1 100644 --- a/services/java/com/android/server/am/StrictModeViolationDialog.java +++ b/services/java/com/android/server/am/StrictModeViolationDialog.java @@ -28,6 +28,7 @@ import android.util.Slog; class StrictModeViolationDialog extends BaseErrorDialog { private final static String TAG = "StrictModeViolationDialog"; + private final ActivityManagerService mService; private final AppErrorResult mResult; private final ProcessRecord mProc; @@ -39,11 +40,13 @@ class StrictModeViolationDialog extends BaseErrorDialog { // dialog static final long DISMISS_TIMEOUT = 1000 * 60 * 1; - public StrictModeViolationDialog(Context context, AppErrorResult result, ProcessRecord app) { + public StrictModeViolationDialog(Context context, ActivityManagerService service, + AppErrorResult result, ProcessRecord app) { super(context); Resources res = context.getResources(); + mService = service; mProc = app; mResult = result; CharSequence name; @@ -83,7 +86,7 @@ class StrictModeViolationDialog extends BaseErrorDialog { private final Handler mHandler = new Handler() { public void handleMessage(Message msg) { - synchronized (mProc) { + synchronized (mService) { if (mProc != null && mProc.crashDialog == StrictModeViolationDialog.this) { mProc.crashDialog = null; } diff --git a/services/java/com/android/server/am/UserStartedState.java b/services/java/com/android/server/am/UserStartedState.java index 3f3ed85..50c8553 100644 --- a/services/java/com/android/server/am/UserStartedState.java +++ b/services/java/com/android/server/am/UserStartedState.java @@ -32,12 +32,17 @@ public class UserStartedState { = new ArrayList<IStopUserCallback>(); public int mState = STATE_BOOTING; + public boolean switching; + public boolean initializing; public UserStartedState(UserHandle handle, boolean initial) { mHandle = handle; } void dump(String prefix, PrintWriter pw) { - pw.print(prefix); pw.print("mState="); pw.println(mState); + pw.print(prefix); pw.print("mState="); pw.print(mState); + if (switching) pw.print(" SWITCHING"); + if (initializing) pw.print(" INITIALIZING"); + pw.println(); } } diff --git a/services/java/com/android/server/dreams/DreamController.java b/services/java/com/android/server/dreams/DreamController.java index 81c80187..6db495a 100644 --- a/services/java/com/android/server/dreams/DreamController.java +++ b/services/java/com/android/server/dreams/DreamController.java @@ -25,7 +25,7 @@ import android.os.Handler; import android.os.IBinder; import android.os.RemoteException; import android.os.IBinder.DeathRecipient; -import android.service.dreams.Dream; +import android.service.dreams.DreamService; import android.service.dreams.IDreamService; import android.util.Slog; import android.view.IWindowManager; @@ -48,11 +48,13 @@ final class DreamController { private final Listener mListener; private final IWindowManager mIWindowManager; - private final Intent mDreamingStartedIntent = new Intent(Dream.ACTION_DREAMING_STARTED) + private final Intent mDreamingStartedIntent = new Intent(Intent.ACTION_DREAMING_STARTED) .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); - private final Intent mDreamingStoppedIntent = new Intent(Dream.ACTION_DREAMING_STOPPED) + private final Intent mDreamingStoppedIntent = new Intent(Intent.ACTION_DREAMING_STOPPED) .addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + private final Intent mCloseNotificationShadeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); + private DreamRecord mCurrentDream; public DreamController(Context context, Handler handler, Listener listener) { @@ -81,6 +83,9 @@ final class DreamController { public void startDream(Binder token, ComponentName name, boolean isTest, int userId) { stopDream(); + // Close the notification shade + mContext.sendBroadcast(mCloseNotificationShadeIntent); + Slog.i(TAG, "Starting dream: name=" + name + ", isTest=" + isTest + ", userId=" + userId); mCurrentDream = new DreamRecord(token, name, isTest, userId); @@ -93,8 +98,7 @@ final class DreamController { return; } - Intent intent = new Intent(Intent.ACTION_MAIN); - intent.addCategory(Dream.CATEGORY_DREAM); + Intent intent = new Intent(DreamService.SERVICE_INTERFACE); intent.setComponent(name); intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); try { diff --git a/services/java/com/android/server/input/InputManagerService.java b/services/java/com/android/server/input/InputManagerService.java index 0b4a721..7b0c452 100644 --- a/services/java/com/android/server/input/InputManagerService.java +++ b/services/java/com/android/server/input/InputManagerService.java @@ -1238,11 +1238,15 @@ public class InputManagerService extends IInputManager.Stub } // Native callback. - private void notifySwitch(long whenNanos, int switchCode, int switchValue) { - switch (switchCode) { - case SW_LID: - mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, switchValue == 0); - break; + private void notifySwitch(long whenNanos, int switchValues, int switchMask) { + if (DEBUG) { + Slog.d(TAG, "notifySwitch: values=" + Integer.toHexString(switchValues) + + ", mask=" + Integer.toHexString(switchMask)); + } + + if ((switchMask & (1 << SW_LID)) != 0) { + final boolean lidOpen = ((switchValues & (1 << SW_LID)) == 0); + mWindowManagerCallbacks.notifyLidSwitchChanged(whenNanos, lidOpen); } } diff --git a/services/java/com/android/server/location/LocationBlacklist.java b/services/java/com/android/server/location/LocationBlacklist.java index 71fa9f9..6ad1a92 100644 --- a/services/java/com/android/server/location/LocationBlacklist.java +++ b/services/java/com/android/server/location/LocationBlacklist.java @@ -78,6 +78,7 @@ public final class LocationBlacklist extends ContentObserver { * (package name matches blacklist, and does not match whitelist) */ public boolean isBlacklisted(String packageName) { + /* synchronized (mLock) { for (String black : mBlacklist) { if (packageName.startsWith(black)) { @@ -91,6 +92,7 @@ public final class LocationBlacklist extends ContentObserver { } } } + */ return false; } diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java index f2748a3..0efdead 100644 --- a/services/java/com/android/server/net/NetworkStatsService.java +++ b/services/java/com/android/server/net/NetworkStatsService.java @@ -104,7 +104,7 @@ import android.os.RemoteException; import android.os.SystemClock; import android.os.UserHandle; import android.provider.Settings; -import android.provider.Settings.Secure; +import android.provider.Settings.Global; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.EventLog; @@ -696,7 +696,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { /** * Update {@link NetworkStatsRecorder} and {@link #mGlobalAlertBytes} to * reflect current {@link #mPersistThreshold} value. Always defers to - * {@link Secure} values when defined. + * {@link Global} values when defined. */ private void updatePersistThresholds() { mDevRecorder.setPersistThreshold(mSettings.getDevPersistBytes(mPersistThreshold)); @@ -1263,7 +1263,7 @@ public class NetworkStatsService extends INetworkStatsService.Stub { /** * Default external settings that read from - * {@link android.provider.Settings.Secure}. + * {@link android.provider.Settings.Global}. */ private static class DefaultNetworkStatsSettings implements NetworkStatsSettings { private final ContentResolver mResolver; diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java index c4cdd07..1eafd9c 100644 --- a/services/java/com/android/server/pm/PackageManagerService.java +++ b/services/java/com/android/server/pm/PackageManagerService.java @@ -5614,7 +5614,7 @@ public class PackageManagerService extends IPackageManager.Stub { int flags, String installerPackageName, Uri verificationURI, ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) { VerificationParams verificationParams = new VerificationParams(verificationURI, null, null, - manifestDigest); + VerificationParams.NO_UID, manifestDigest); installPackageWithVerificationAndEncryption(packageURI, observer, flags, installerPackageName, verificationParams, encryptionParams); } @@ -6438,6 +6438,10 @@ public class PackageManagerService extends IPackageManager.Stub { verification.putExtra(Intent.EXTRA_REFERRER, verificationParams.getReferrer()); } + if (verificationParams.getOriginatingUid() >= 0) { + verification.putExtra(Intent.EXTRA_ORIGINATING_UID, + verificationParams.getOriginatingUid()); + } if (verificationParams.getInstallerUid() >= 0) { verification.putExtra(PackageManager.EXTRA_VERIFICATION_INSTALLER_UID, verificationParams.getInstallerUid()); @@ -10015,16 +10019,16 @@ public class PackageManagerService extends IPackageManager.Stub { } if (loc == PackageHelper.APP_INSTALL_AUTO || loc == PackageHelper.APP_INSTALL_INTERNAL || loc == PackageHelper.APP_INSTALL_EXTERNAL) { - android.provider.Settings.System.putInt(mContext.getContentResolver(), - android.provider.Settings.Secure.DEFAULT_INSTALL_LOCATION, loc); + android.provider.Settings.Global.putInt(mContext.getContentResolver(), + android.provider.Settings.Global.DEFAULT_INSTALL_LOCATION, loc); return true; } return false; } public int getInstallLocation() { - return android.provider.Settings.System.getInt(mContext.getContentResolver(), - android.provider.Settings.Secure.DEFAULT_INSTALL_LOCATION, + return android.provider.Settings.Global.getInt(mContext.getContentResolver(), + android.provider.Settings.Global.DEFAULT_INSTALL_LOCATION, PackageHelper.APP_INSTALL_AUTO); } @@ -10116,8 +10120,9 @@ public class PackageManagerService extends IPackageManager.Stub { */ private boolean isPermissionEnforcedDefault(String permission) { if (READ_EXTERNAL_STORAGE.equals(permission)) { - return Secure.getInt(mContext.getContentResolver(), - Secure.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT, 0) != 0; + return android.provider.Settings.Global.getInt(mContext.getContentResolver(), + android.provider.Settings.Global.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT, 0) + != 0; } else { return true; } diff --git a/services/java/com/android/server/pm/PackageSettingBase.java b/services/java/com/android/server/pm/PackageSettingBase.java index d8f7345..6a363a8 100644 --- a/services/java/com/android/server/pm/PackageSettingBase.java +++ b/services/java/com/android/server/pm/PackageSettingBase.java @@ -20,6 +20,7 @@ import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageUserState; import android.content.pm.UserInfo; import android.util.SparseArray; @@ -64,7 +65,8 @@ class PackageSettingBase extends GrantedPermissions { boolean permissionsFixed; boolean haveGids; - private static final PackageUserState DEFAULT_USER_STATE = new PackageUserState(); + private static final PackageUserState DEFAULT_USER_STATE = new PackageUserState(false); + private static final PackageUserState DEFAULT_SYSTEM_USER_STATE = new PackageUserState(true); // Whether this package is currently stopped, thus can not be // started until explicitly launched by the user. @@ -174,7 +176,7 @@ class PackageSettingBase extends GrantedPermissions { private PackageUserState modifyUserState(int userId) { PackageUserState state = userState.get(userId); if (state == null) { - state = new PackageUserState(); + state = new PackageUserState((pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0); userState.put(userId, state); } return state; @@ -182,7 +184,11 @@ class PackageSettingBase extends GrantedPermissions { public PackageUserState readUserState(int userId) { PackageUserState state = userState.get(userId); - return state != null ? state : DEFAULT_USER_STATE; + if (state != null) { + return state; + } + return ((pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0) + ? DEFAULT_SYSTEM_USER_STATE : DEFAULT_USER_STATE; } void setEnabled(int state, int userId) { diff --git a/services/java/com/android/server/pm/Settings.java b/services/java/com/android/server/pm/Settings.java index 2fb853a..bdf5044 100644 --- a/services/java/com/android/server/pm/Settings.java +++ b/services/java/com/android/server/pm/Settings.java @@ -2609,10 +2609,11 @@ final class Settings { pw.print(" installerPackageName="); pw.println(ps.installerPackageName); } pw.print(" signatures="); pw.println(ps.signatures); - pw.print(" permissionsFixed="); pw.println(ps.permissionsFixed); - pw.print(" haveGids="); pw.println(ps.haveGids); + pw.print(" permissionsFixed="); pw.print(ps.permissionsFixed); + pw.print(" haveGids="); pw.print(ps.haveGids); + pw.print(" installStatus="); pw.println(ps.installStatus); pw.print(" pkgFlags="); printFlags(pw, ps.pkgFlags, FLAG_DUMP_SPEC); - pw.print(" installStatus="); pw.println(ps.installStatus); + pw.println(); for (UserInfo user : users) { pw.print(" User "); pw.print(user.id); pw.print(": "); pw.print(" installed="); diff --git a/services/java/com/android/server/pm/UserManagerService.java b/services/java/com/android/server/pm/UserManagerService.java index 2edc700..a0326c5 100644 --- a/services/java/com/android/server/pm/UserManagerService.java +++ b/services/java/com/android/server/pm/UserManagerService.java @@ -16,9 +16,6 @@ package com.android.server.pm; -import static android.os.ParcelFileDescriptor.MODE_CREATE; -import static android.os.ParcelFileDescriptor.MODE_READ_WRITE; - import com.android.internal.util.ArrayUtils; import com.android.internal.util.FastXmlSerializer; @@ -35,7 +32,6 @@ import android.os.Binder; import android.os.Environment; import android.os.FileUtils; import android.os.IUserManager; -import android.os.ParcelFileDescriptor; import android.os.Process; import android.os.RemoteException; import android.os.UserHandle; @@ -74,6 +70,7 @@ public class UserManagerService extends IUserManager.Stub { private static final String ATTR_LAST_LOGGED_IN_TIME = "lastLoggedIn"; private static final String ATTR_SERIAL_NO = "serialNumber"; private static final String ATTR_NEXT_SERIAL_NO = "nextSerialNumber"; + private static final String ATTR_PARTIAL = "partial"; private static final String TAG_USERS = "users"; private static final String TAG_USER = "user"; @@ -132,24 +129,40 @@ public class UserManagerService extends IUserManager.Stub { private UserManagerService(Context context, PackageManagerService pm, Object installLock, Object packagesLock, File dataDir, File baseUserPath) { - synchronized (UserManagerService.class) { - mContext = context; - mPm = pm; - mInstallLock = installLock; - mPackagesLock = packagesLock; - mUsersDir = new File(dataDir, USER_INFO_DIR); - mUsersDir.mkdirs(); - // Make zeroth user directory, for services to migrate their files to that location - File userZeroDir = new File(mUsersDir, "0"); - userZeroDir.mkdirs(); - mBaseUserPath = baseUserPath; - FileUtils.setPermissions(mUsersDir.toString(), - FileUtils.S_IRWXU|FileUtils.S_IRWXG - |FileUtils.S_IROTH|FileUtils.S_IXOTH, - -1, -1); - mUserListFile = new File(mUsersDir, USER_LIST_FILENAME); - readUserList(); - sInstance = this; + mContext = context; + mPm = pm; + mInstallLock = installLock; + mPackagesLock = packagesLock; + synchronized (mInstallLock) { + synchronized (mPackagesLock) { + mUsersDir = new File(dataDir, USER_INFO_DIR); + mUsersDir.mkdirs(); + // Make zeroth user directory, for services to migrate their files to that location + File userZeroDir = new File(mUsersDir, "0"); + userZeroDir.mkdirs(); + mBaseUserPath = baseUserPath; + FileUtils.setPermissions(mUsersDir.toString(), + FileUtils.S_IRWXU|FileUtils.S_IRWXG + |FileUtils.S_IROTH|FileUtils.S_IXOTH, + -1, -1); + mUserListFile = new File(mUsersDir, USER_LIST_FILENAME); + readUserListLocked(); + // Prune out any partially created users. + ArrayList<UserInfo> partials = new ArrayList<UserInfo>(); + for (int i = 0; i < mUsers.size(); i++) { + UserInfo ui = mUsers.valueAt(i); + if (ui.partial && i != 0) { + partials.add(ui); + } + } + for (int i = 0; i < partials.size(); i++) { + UserInfo ui = partials.get(i); + Slog.w(LOG_TAG, "Removing partially created user #" + i + + " (name=" + ui.name + ")"); + removeUserStateLocked(ui.id); + } + sInstance = this; + } } } @@ -159,8 +172,12 @@ public class UserManagerService extends IUserManager.Stub { synchronized (mPackagesLock) { ArrayList<UserInfo> users = new ArrayList<UserInfo>(mUsers.size()); for (int i = 0; i < mUsers.size(); i++) { - if (!excludeDying || !mRemovingUserIds.contains(mUsers.keyAt(i))) { - users.add(mUsers.valueAt(i)); + UserInfo ui = mUsers.valueAt(i); + if (ui.partial) { + continue; + } + if (!excludeDying || !mRemovingUserIds.contains(ui.id)) { + users.add(ui); } } return users; @@ -179,7 +196,12 @@ public class UserManagerService extends IUserManager.Stub { * Should be locked on mUsers before calling this. */ private UserInfo getUserInfoLocked(int userId) { - return mUsers.get(userId); + UserInfo ui = mUsers.get(userId); + if (ui != null && ui.partial) { + Slog.w(LOG_TAG, "getUserInfo: unknown user #" + userId); + return null; + } + return ui; } public boolean exists(int userId) { @@ -191,14 +213,22 @@ public class UserManagerService extends IUserManager.Stub { @Override public void setUserName(int userId, String name) { checkManageUsersPermission("rename users"); + boolean changed = false; synchronized (mPackagesLock) { UserInfo info = mUsers.get(userId); + if (info == null || info.partial) { + Slog.w(LOG_TAG, "setUserName: unknown user #" + userId); + return; + } if (name != null && !name.equals(info.name)) { info.name = name; writeUserLocked(info); + changed = true; } } - sendUserInfoChangedBroadcast(userId); + if (changed) { + sendUserInfoChangedBroadcast(userId); + } } @Override @@ -206,7 +236,10 @@ public class UserManagerService extends IUserManager.Stub { checkManageUsersPermission("update users"); synchronized (mPackagesLock) { UserInfo info = mUsers.get(userId); - if (info == null) return; + if (info == null || info.partial) { + Slog.w(LOG_TAG, "setUserIcon: unknown user #" + userId); + return; + } writeBitmapLocked(info, bitmap); writeUserLocked(info); } @@ -225,7 +258,13 @@ public class UserManagerService extends IUserManager.Stub { checkManageUsersPermission("read users"); synchronized (mPackagesLock) { UserInfo info = mUsers.get(userId); - if (info == null || info.iconPath == null) return null; + if (info == null || info.partial) { + Slog.w(LOG_TAG, "getUserIcon: unknown user #" + userId); + return null; + } + if (info.iconPath == null) { + return null; + } return BitmapFactory.decodeFile(info.iconPath); } } @@ -239,7 +278,7 @@ public class UserManagerService extends IUserManager.Stub { // Erase any guest user that currently exists for (int i = 0; i < mUsers.size(); i++) { UserInfo user = mUsers.valueAt(i); - if (user.isGuest()) { + if (!user.partial && user.isGuest()) { if (!enable) { removeUser(user.id); } @@ -271,7 +310,10 @@ public class UserManagerService extends IUserManager.Stub { checkManageUsersPermission("makeInitialized"); synchronized (mPackagesLock) { UserInfo info = mUsers.get(userId); - if (info != null && (info.flags&UserInfo.FLAG_INITIALIZED) == 0) { + if (info == null || info.partial) { + Slog.w(LOG_TAG, "makeInitialized: unknown user #" + userId); + } + if ((info.flags&UserInfo.FLAG_INITIALIZED) == 0) { info.flags |= UserInfo.FLAG_INITIALIZED; writeUserLocked(info); } @@ -453,6 +495,9 @@ public class UserManagerService extends IUserManager.Stub { if (userInfo.iconPath != null) { serializer.attribute(null, ATTR_ICON_PATH, userInfo.iconPath); } + if (userInfo.partial) { + serializer.attribute(null, ATTR_PARTIAL, "true"); + } serializer.startTag(null, TAG_NAME); serializer.text(userInfo.name); @@ -516,6 +561,7 @@ public class UserManagerService extends IUserManager.Stub { String iconPath = null; long creationTime = 0L; long lastLoggedInTime = 0L; + boolean partial = false; FileInputStream fis = null; try { @@ -546,6 +592,10 @@ public class UserManagerService extends IUserManager.Stub { iconPath = parser.getAttributeValue(null, ATTR_ICON_PATH); creationTime = readLongAttribute(parser, ATTR_CREATION_TIME, 0); lastLoggedInTime = readLongAttribute(parser, ATTR_LAST_LOGGED_IN_TIME, 0); + String valueString = parser.getAttributeValue(null, ATTR_PARTIAL); + if ("true".equals(valueString)) { + partial = true; + } while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { @@ -562,6 +612,7 @@ public class UserManagerService extends IUserManager.Stub { userInfo.serialNumber = serialNumber; userInfo.creationTime = creationTime; userInfo.lastLoggedInTime = lastLoggedInTime; + userInfo.partial = partial; return userInfo; } catch (IOException ioe) { @@ -613,11 +664,14 @@ public class UserManagerService extends IUserManager.Stub { userInfo.serialNumber = mNextSerialNumber++; long now = System.currentTimeMillis(); userInfo.creationTime = (now > EPOCH_PLUS_30_YEARS) ? now : 0; + userInfo.partial = true; mUsers.put(userId, userInfo); writeUserListLocked(); writeUserLocked(userInfo); - updateUserIdsLocked(); mPm.createNewUserLILPw(userId, userPath); + userInfo.partial = false; + writeUserLocked(userInfo); + updateUserIdsLocked(); } } if (userInfo != null) { @@ -670,19 +724,7 @@ public class UserManagerService extends IUserManager.Stub { void finishRemoveUser(int userHandle) { synchronized (mInstallLock) { synchronized (mPackagesLock) { - // Cleanup package manager settings - mPm.cleanUpUserLILPw(userHandle); - - // Remove this user from the list - mUsers.remove(userHandle); - mRemovingUserIds.remove(userHandle); - // Remove user file - AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + ".xml")); - userFile.delete(); - // Update the user list - writeUserListLocked(); - updateUserIdsLocked(); - removeDirectoryRecursive(Environment.getUserSystemDirectory(userHandle)); + removeUserStateLocked(userHandle); } } @@ -698,6 +740,22 @@ public class UserManagerService extends IUserManager.Stub { } } + private void removeUserStateLocked(int userHandle) { + // Cleanup package manager settings + mPm.cleanUpUserLILPw(userHandle); + + // Remove this user from the list + mUsers.remove(userHandle); + mRemovingUserIds.remove(userHandle); + // Remove user file + AtomicFile userFile = new AtomicFile(new File(mUsersDir, userHandle + ".xml")); + userFile.delete(); + // Update the user list + writeUserListLocked(); + updateUserIdsLocked(); + removeDirectoryRecursive(Environment.getUserSystemDirectory(userHandle)); + } + private void removeDirectoryRecursive(File parent) { if (parent.isDirectory()) { String[] files = parent.list(); @@ -732,9 +790,17 @@ public class UserManagerService extends IUserManager.Stub { * Caches the list of user ids in an array, adjusting the array size when necessary. */ private void updateUserIdsLocked() { - int[] newUsers = new int[mUsers.size()]; + int num = 0; + for (int i = 0; i < mUsers.size(); i++) { + if (!mUsers.valueAt(i).partial) { + num++; + } + } + int[] newUsers = new int[num]; for (int i = 0; i < mUsers.size(); i++) { - newUsers[i] = mUsers.keyAt(i); + if (!mUsers.valueAt(i).partial) { + newUsers[i] = mUsers.keyAt(i); + } } mUserIds = newUsers; } @@ -747,7 +813,11 @@ public class UserManagerService extends IUserManager.Stub { synchronized (mPackagesLock) { UserInfo user = mUsers.get(userId); long now = System.currentTimeMillis(); - if (user != null && now > EPOCH_PLUS_30_YEARS) { + if (user == null || user.partial) { + Slog.w(LOG_TAG, "userForeground: unknown user #" + userId); + return; + } + if (now > EPOCH_PLUS_30_YEARS) { user.lastLoggedInTime = now; writeUserLocked(user); } @@ -793,7 +863,9 @@ public class UserManagerService extends IUserManager.Stub { UserInfo user = mUsers.valueAt(i); if (user == null) continue; pw.print(" "); pw.print(user); - pw.println(mRemovingUserIds.contains(mUsers.keyAt(i)) ? " <removing> " : ""); + if (mRemovingUserIds.contains(mUsers.keyAt(i))) pw.print(" <removing> "); + if (user.partial) pw.print(" <partial>"); + pw.println(); pw.print(" Created: "); if (user.creationTime == 0) { pw.println("<unknown>"); diff --git a/services/java/com/android/server/power/PowerManagerService.java b/services/java/com/android/server/power/PowerManagerService.java index ad138e8..9052e0e 100644 --- a/services/java/com/android/server/power/PowerManagerService.java +++ b/services/java/com/android/server/power/PowerManagerService.java @@ -51,7 +51,6 @@ import android.os.SystemClock; import android.os.UserHandle; import android.os.WorkSource; import android.provider.Settings; -import android.service.dreams.Dream; import android.util.EventLog; import android.util.Log; import android.util.Slog; @@ -363,8 +362,8 @@ public final class PowerManagerService extends IPowerManager.Stub mContext.registerReceiver(new BootCompletedReceiver(), filter, null, mHandler); filter = new IntentFilter(); - filter.addAction(Dream.ACTION_DREAMING_STARTED); - filter.addAction(Dream.ACTION_DREAMING_STOPPED); + filter.addAction(Intent.ACTION_DREAMING_STARTED); + filter.addAction(Intent.ACTION_DREAMING_STOPPED); mContext.registerReceiver(new DreamReceiver(), filter, null, mHandler); filter = new IntentFilter(); diff --git a/services/java/com/android/server/updates/ConfigUpdateInstallReceiver.java b/services/java/com/android/server/updates/ConfigUpdateInstallReceiver.java index e07230d..4480151 100644 --- a/services/java/com/android/server/updates/ConfigUpdateInstallReceiver.java +++ b/services/java/com/android/server/updates/ConfigUpdateInstallReceiver.java @@ -126,7 +126,7 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver { CertificateFactory cf = CertificateFactory.getInstance("X.509"); return (X509Certificate) cf.generateCertificate(istream); } catch (CertificateException e) { - throw new IllegalStateException("Got malformed certificate from settings, ignoring", e); + throw new IllegalStateException("Got malformed certificate from settings, ignoring"); } } @@ -167,7 +167,7 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver { String strVersion = IoUtils.readFileAsString(updateVersion.getCanonicalPath()).trim(); return Integer.parseInt(strVersion); } catch (IOException e) { - Slog.i(TAG, "Couldn't find current metadata, assuming first update", e); + Slog.i(TAG, "Couldn't find current metadata, assuming first update"); return 0; } } @@ -181,7 +181,7 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver { try { return IoUtils.readFileAsString(updateContent.getCanonicalPath()).trim(); } catch (IOException e) { - Slog.i(TAG, "Failed to read current content, assuming first update!", e); + Slog.i(TAG, "Failed to read current content, assuming first update!"); return null; } } diff --git a/services/java/com/android/server/updates/SmsShortCodesInstallReceiver.java b/services/java/com/android/server/updates/SmsShortCodesInstallReceiver.java new file mode 100644 index 0000000..0f14f57 --- /dev/null +++ b/services/java/com/android/server/updates/SmsShortCodesInstallReceiver.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2012 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 com.android.server.updates; + +public class SmsShortCodesInstallReceiver extends ConfigUpdateInstallReceiver { + + public SmsShortCodesInstallReceiver() { + super("/data/misc/sms/", "codes", "metadata/", "version"); + } +} diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java index efedbd8..23ce52e 100755 --- a/services/java/com/android/server/wm/WindowManagerService.java +++ b/services/java/com/android/server/wm/WindowManagerService.java @@ -74,7 +74,6 @@ import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Region; import android.hardware.display.DisplayManager; -import android.hardware.input.InputManager; import android.os.Binder; import android.os.Bundle; import android.os.Debug; @@ -2749,7 +2748,8 @@ public class WindowManagerService extends IWindowManager.Stub } } - if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": " + win.mAttrs); + if (DEBUG_LAYOUT) Slog.v(TAG, "Relayout " + win + ": viewVisibility=" + viewVisibility + + " " + requestedWidth + "x" + requestedHeight + " " + win.mAttrs); win.mEnforceSizeCompat = (win.mAttrs.flags & FLAG_COMPATIBLE_WINDOW) != 0; @@ -4036,7 +4036,8 @@ public class WindowManagerService extends IWindowManager.Stub } changed = mFocusedApp != newFocus; mFocusedApp = newFocus; - if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp); + if (DEBUG_FOCUS) Slog.v(TAG, "Set focused app to: " + mFocusedApp + + " moveFocusNow=" + moveFocusNow); if (changed) { mInputMonitor.setFocusedAppLw(newFocus); } @@ -8296,7 +8297,8 @@ public class WindowManagerService extends IWindowManager.Stub if (DEBUG_LAYOUT && !win.mLayoutAttached) { Slog.v(TAG, "1ST PASS " + win + ": gone=" + gone + " mHaveFrame=" + win.mHaveFrame - + " mLayoutAttached=" + win.mLayoutAttached); + + " mLayoutAttached=" + win.mLayoutAttached + + " screen changed=" + win.isConfigDiff(ActivityInfo.CONFIG_SCREEN_SIZE)); final AppWindowToken atoken = win.mAppToken; if (gone) Slog.v(TAG, " GONE: mViewVisibility=" + win.mViewVisibility + " mRelayoutCalled=" @@ -8318,6 +8320,7 @@ public class WindowManagerService extends IWindowManager.Stub // windows, since that means "perform layout as normal, // just don't display"). if (!gone || !win.mHaveFrame || win.mLayoutNeeded + || win.isConfigDiff(ActivityInfo.CONFIG_SCREEN_SIZE) || win.mAttrs.type == TYPE_UNIVERSE_BACKGROUND) { if (!win.mLayoutAttached) { if (initial) { @@ -8753,10 +8756,7 @@ public class WindowManagerService extends IWindowManager.Stub !w.mLastContentInsets.equals(w.mContentInsets); w.mVisibleInsetsChanged |= !w.mLastVisibleInsets.equals(w.mVisibleInsets); - boolean configChanged = - w.mConfiguration != mCurConfiguration - && (w.mConfiguration == null - || mCurConfiguration.diff(w.mConfiguration) != 0); + boolean configChanged = w.isConfigChanged(); if (DEBUG_CONFIGURATION && configChanged) { Slog.v(TAG, "Win " + w + " config changed: " + mCurConfiguration); @@ -9254,10 +9254,7 @@ public class WindowManagerService extends IWindowManager.Stub if (DEBUG_RESIZE || DEBUG_ORIENTATION) Slog.v(TAG, "Reporting new frame to " + win + ": " + win.mCompatFrame); int diff = 0; - boolean configChanged = - win.mConfiguration != mCurConfiguration - && (win.mConfiguration == null - || (diff=mCurConfiguration.diff(win.mConfiguration)) != 0); + boolean configChanged = win.isConfigChanged(); if ((DEBUG_RESIZE || DEBUG_ORIENTATION || DEBUG_CONFIGURATION) && configChanged) { Slog.i(TAG, "Sending new config to window " + win + ": " diff --git a/services/java/com/android/server/wm/WindowState.java b/services/java/com/android/server/wm/WindowState.java index ac958b8..9963d14 100644 --- a/services/java/com/android/server/wm/WindowState.java +++ b/services/java/com/android/server/wm/WindowState.java @@ -574,6 +574,7 @@ final class WindowState implements WindowManagerPolicy.WindowState { return mAttrs; } + @Override public boolean getNeedsMenuLw(WindowManagerPolicy.WindowState bottom) { int index = -1; WindowState ws = this; @@ -612,6 +613,7 @@ final class WindowState implements WindowManagerPolicy.WindowState { return mLayer; } + @Override public IApplicationToken getAppToken() { return mAppToken != null ? mAppToken.appToken : null; } @@ -801,12 +803,13 @@ final class WindowState implements WindowManagerPolicy.WindowState { return mWinAnimator.mAnimation != null; } + @Override public boolean isGoneForLayoutLw() { final AppWindowToken atoken = mAppToken; return mViewVisibility == View.GONE || !mRelayoutCalled || (atoken == null && mRootToken.hidden) - || (atoken != null && atoken.hiddenRequested) + || (atoken != null && (atoken.hiddenRequested || atoken.hidden)) || mAttachedHidden || mExiting || mDestroying; } @@ -849,6 +852,18 @@ final class WindowState implements WindowManagerPolicy.WindowState { mFrame.right >= screenWidth && mFrame.bottom >= screenHeight; } + boolean isConfigChanged() { + return mConfiguration != mService.mCurConfiguration + && (mConfiguration == null + || (mConfiguration.diff(mService.mCurConfiguration) != 0)); + } + + boolean isConfigDiff(int mask) { + return mConfiguration != mService.mCurConfiguration + && mConfiguration != null + && (mConfiguration.diff(mService.mCurConfiguration) & mask) != 0; + } + void removeLocked() { disposeInputChannel(); |