diff options
Diffstat (limited to 'services/java')
17 files changed, 460 insertions, 52 deletions
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index ffc3672..f320562 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -2347,28 +2347,6 @@ public class ConnectivityService extends IConnectivityManager.Stub { } } - for (RouteInfo r : routeDiff.added) { - if (isLinkDefault || ! r.isDefaultRoute()) { - addRoute(newLp, r, TO_DEFAULT_TABLE); - } else { - // add to a secondary route table - addRoute(newLp, r, TO_SECONDARY_TABLE); - - // many radios add a default route even when we don't want one. - // remove the default route unless somebody else has asked for it - String ifaceName = newLp.getInterfaceName(); - if (TextUtils.isEmpty(ifaceName) == false && mAddedRoutes.contains(r) == false) { - if (VDBG) log("Removing " + r + " for interface " + ifaceName); - try { - mNetd.removeRoute(ifaceName, r); - } catch (Exception e) { - // never crash - catch them all - if (DBG) loge("Exception trying to remove a route: " + e); - } - } - } - } - if (!isLinkDefault) { // handle DNS routes if (routesChanged) { @@ -2393,6 +2371,29 @@ public class ConnectivityService extends IConnectivityManager.Stub { } } } + + for (RouteInfo r : routeDiff.added) { + if (isLinkDefault || ! r.isDefaultRoute()) { + addRoute(newLp, r, TO_DEFAULT_TABLE); + } else { + // add to a secondary route table + addRoute(newLp, r, TO_SECONDARY_TABLE); + + // many radios add a default route even when we don't want one. + // remove the default route unless somebody else has asked for it + String ifaceName = newLp.getInterfaceName(); + if (TextUtils.isEmpty(ifaceName) == false && mAddedRoutes.contains(r) == false) { + if (VDBG) log("Removing " + r + " for interface " + ifaceName); + try { + mNetd.removeRoute(ifaceName, r); + } catch (Exception e) { + // never crash - catch them all + if (DBG) loge("Exception trying to remove a route: " + e); + } + } + } + } + return routesChanged; } @@ -3045,7 +3046,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { } public void setGlobalProxy(ProxyProperties proxyProperties) { - enforceChangePermission(); + enforceConnectivityInternalPermission(); synchronized (mProxyLock) { if (proxyProperties == mGlobalProxy) return; if (proxyProperties != null && proxyProperties.equals(mGlobalProxy)) return; @@ -3063,10 +3064,15 @@ public class ConnectivityService extends IConnectivityManager.Stub { mGlobalProxy = null; } ContentResolver res = mContext.getContentResolver(); - 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); + final long token = Binder.clearCallingIdentity(); + try { + 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); + } finally { + Binder.restoreCallingIdentity(token); + } } if (mGlobalProxy == null) { diff --git a/services/java/com/android/server/LocationManagerService.java b/services/java/com/android/server/LocationManagerService.java index bcb7cb7..1e1cf5a 100644 --- a/services/java/com/android/server/LocationManagerService.java +++ b/services/java/com/android/server/LocationManagerService.java @@ -54,19 +54,17 @@ import android.os.Message; import android.os.PowerManager; import android.os.Process; import android.os.RemoteException; -import android.os.ServiceManager; import android.os.SystemClock; import android.os.UserHandle; import android.os.WorkSource; import android.provider.Settings; import android.util.Log; import android.util.Slog; - -import com.android.internal.app.IAppOpsService; import com.android.internal.content.PackageMonitor; import com.android.internal.location.ProviderProperties; import com.android.internal.location.ProviderRequest; import com.android.server.location.GeocoderProxy; +import com.android.server.location.GeofenceProxy; import com.android.server.location.GeofenceManager; import com.android.server.location.GpsLocationProvider; import com.android.server.location.LocationBlacklist; @@ -338,11 +336,11 @@ public class LocationManagerService extends ILocationManager.Stub { addProviderLocked(passiveProvider); mEnabledProviders.add(passiveProvider.getName()); mPassiveProvider = passiveProvider; + // Create a gps location provider + GpsLocationProvider gpsProvider = new GpsLocationProvider(mContext, this, + mLocationHandler.getLooper()); if (GpsLocationProvider.isSupported()) { - // Create a gps location provider - GpsLocationProvider gpsProvider = new GpsLocationProvider(mContext, this, - mLocationHandler.getLooper()); mGpsStatusProvider = gpsProvider.getGpsStatusProvider(); mNetInitiatedListener = gpsProvider.getNetInitiatedListener(); addProviderLocked(gpsProvider); @@ -406,6 +404,14 @@ public class LocationManagerService extends ILocationManager.Stub { if (mGeocodeProvider == null) { Slog.e(TAG, "no geocoder provider found"); } + + // bind to geofence provider + GeofenceProxy provider = GeofenceProxy.createAndBind(mContext, providerPackageNames, + mLocationHandler, gpsProvider.getGpsGeofenceProxy()); + if (provider == null) { + Slog.e(TAG, "no geofence provider found"); + } + } /** diff --git a/services/java/com/android/server/accounts/AccountManagerService.java b/services/java/com/android/server/accounts/AccountManagerService.java index 14d808f..fd7cd78 100644 --- a/services/java/com/android/server/accounts/AccountManagerService.java +++ b/services/java/com/android/server/accounts/AccountManagerService.java @@ -22,6 +22,7 @@ import android.accounts.AccountAndUser; import android.accounts.AccountAuthenticatorResponse; import android.accounts.AccountManager; import android.accounts.AuthenticatorDescription; +import android.accounts.CantAddAccountActivity; import android.accounts.GrantCredentialsPermissionActivity; import android.accounts.IAccountAuthenticator; import android.accounts.IAccountAuthenticatorResponse; @@ -1456,6 +1457,14 @@ public class AccountManagerService "User is not allowed to add an account!"); } catch (RemoteException re) { } + Intent cantAddAccount = new Intent(mContext, CantAddAccountActivity.class); + cantAddAccount.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + long identityToken = clearCallingIdentity(); + try { + mContext.startActivityAsUser(cantAddAccount, UserHandle.CURRENT); + } finally { + restoreCallingIdentity(identityToken); + } return; } diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index cc7905c..2417cff 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -4577,7 +4577,7 @@ public final class ActivityManagerService extends ActivityManagerNative public String getCallingPackage(IBinder token) { synchronized (this) { ActivityRecord r = getCallingRecordLocked(token); - return r != null && r.app != null ? r.info.packageName : null; + return r != null ? r.info.packageName : null; } } diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java index 3d2e912..0f1700d 100644 --- a/services/java/com/android/server/am/ActivityStack.java +++ b/services/java/com/android/server/am/ActivityStack.java @@ -47,6 +47,7 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; +import android.net.Uri; import android.os.Binder; import android.os.Bundle; import android.os.Handler; @@ -4600,11 +4601,13 @@ final class ActivityStack { private final void logStartActivity(int tag, ActivityRecord r, TaskRecord task) { + final Uri data = r.intent.getData(); + final String strData = data != null ? data.toSafeString() : null; + EventLog.writeEvent(tag, r.userId, System.identityHashCode(r), task.taskId, r.shortComponentName, r.intent.getAction(), - r.intent.getType(), r.intent.getDataString(), - r.intent.getFlags()); + r.intent.getType(), strData, r.intent.getFlags()); } /** diff --git a/services/java/com/android/server/content/ContentService.java b/services/java/com/android/server/content/ContentService.java index 68cf5fc..f82cf01 100644 --- a/services/java/com/android/server/content/ContentService.java +++ b/services/java/com/android/server/content/ContentService.java @@ -459,7 +459,7 @@ public final class ContentService extends IContentService.Stub { try { SyncManager syncManager = getSyncManager(); if (syncManager != null) { - return syncManager.getSyncStorageEngine().getIsSyncable( + return syncManager.getIsSyncable( account, userId, providerName); } } finally { diff --git a/services/java/com/android/server/content/SyncManager.java b/services/java/com/android/server/content/SyncManager.java index b3f9bf1..1c883ec 100644 --- a/services/java/com/android/server/content/SyncManager.java +++ b/services/java/com/android/server/content/SyncManager.java @@ -21,6 +21,7 @@ import android.accounts.AccountAndUser; import android.accounts.AccountManager; import android.app.ActivityManager; import android.app.AlarmManager; +import android.app.AppGlobals; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; @@ -41,6 +42,7 @@ import android.content.SyncInfo; import android.content.SyncResult; import android.content.SyncStatusInfo; import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ProviderInfo; import android.content.pm.RegisteredServicesCache; @@ -491,6 +493,36 @@ public class SyncManager { return mSyncStorageEngine; } + public int getIsSyncable(Account account, int userId, String providerName) { + int isSyncable = mSyncStorageEngine.getIsSyncable(account, userId, providerName); + UserInfo userInfo = UserManager.get(mContext).getUserInfo(userId); + + // If it's not a restricted user, return isSyncable + if (userInfo == null || !userInfo.isRestricted()) return isSyncable; + + // Else check if the sync adapter has opted-in or not + RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo = + mSyncAdapters.getServiceInfo( + SyncAdapterType.newKey(providerName, account.type), userId); + if (syncAdapterInfo == null) return isSyncable; + + PackageInfo pInfo = null; + try { + pInfo = AppGlobals.getPackageManager().getPackageInfo( + syncAdapterInfo.componentName.getPackageName(), 0, userId); + if (pInfo == null) return isSyncable; + } catch (RemoteException re) { + // Shouldn't happen + return isSyncable; + } + if (pInfo.restrictedAccountType != null + && pInfo.restrictedAccountType.equals(account.type)) { + return isSyncable; + } else { + return 0; + } + } + private void ensureAlarmService() { if (mAlarmService == null) { mAlarmService = (AlarmManager)mContext.getSystemService(Context.ALARM_SERVICE); @@ -608,7 +640,7 @@ public class SyncManager { } for (String authority : syncableAuthorities) { - int isSyncable = mSyncStorageEngine.getIsSyncable(account.account, account.userId, + int isSyncable = getIsSyncable(account.account, account.userId, authority); if (isSyncable == 0) { continue; @@ -1930,7 +1962,7 @@ public class SyncManager { continue; } - if (mSyncStorageEngine.getIsSyncable(info.account, info.userId, info.authority) + if (getIsSyncable(info.account, info.userId, info.authority) == 0) { continue; } @@ -2069,7 +2101,7 @@ public class SyncManager { } // drop this sync request if it isn't syncable - int syncableState = mSyncStorageEngine.getIsSyncable( + int syncableState = getIsSyncable( op.account, op.userId, op.authority); if (syncableState == 0) { operationIterator.remove(); diff --git a/services/java/com/android/server/location/GeofenceProxy.java b/services/java/com/android/server/location/GeofenceProxy.java new file mode 100644 index 0000000..36e9fcc --- /dev/null +++ b/services/java/com/android/server/location/GeofenceProxy.java @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2013 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.location; + +import android.content.ComponentName; +import android.content.Intent; +import android.content.ServiceConnection; +import android.hardware.location.GeofenceHardwareService; +import android.hardware.location.IGeofenceHardware; +import android.location.IGeofenceProvider; +import android.location.IGpsGeofenceHardware; +import android.content.Context; +import android.os.Handler; +import android.os.IBinder; +import android.os.Message; +import android.os.RemoteException; +import android.os.UserHandle; +import android.util.Log; +import com.android.server.ServiceWatcher; + +import java.util.List; + +/** + * @hide + */ +public final class GeofenceProxy { + private static final String TAG = "GeofenceProxy"; + private static final String SERVICE_ACTION = + "com.android.location.service.GeofenceProvider"; + private ServiceWatcher mServiceWatcher; + private Context mContext; + private IGeofenceHardware mGeofenceHardware; + private IGpsGeofenceHardware mGpsGeofenceHardware; + + private static final int GEOFENCE_PROVIDER_CONNECTED = 1; + private static final int GEOFENCE_HARDWARE_CONNECTED = 2; + private static final int GEOFENCE_HARDWARE_DISCONNECTED = 3; + private static final int GEOFENCE_GPS_HARDWARE_CONNECTED = 4; + private static final int GEOFENCE_GPS_HARDWARE_DISCONNECTED = 5; + + private Runnable mRunnable = new Runnable() { + @Override + public void run() { + mHandler.sendEmptyMessage(GEOFENCE_PROVIDER_CONNECTED); + } + }; + + public static GeofenceProxy createAndBind(Context context, + List<String> initialPackageNames, Handler handler, IGpsGeofenceHardware gpsGeofence) { + GeofenceProxy proxy = new GeofenceProxy(context, initialPackageNames, handler, gpsGeofence); + if (proxy.bindGeofenceProvider()) { + return proxy; + } else { + return null; + } + } + + private GeofenceProxy(Context context, List<String> initialPackageName, Handler handler, + IGpsGeofenceHardware gpsGeofence) { + mContext = context; + mServiceWatcher = new ServiceWatcher(context, TAG, SERVICE_ACTION, initialPackageName, + mRunnable, handler); + mGpsGeofenceHardware = gpsGeofence; + bindHardwareGeofence(); + } + + private boolean bindGeofenceProvider() { + return mServiceWatcher.start(); + } + + private IGeofenceProvider getGeofenceProviderService() { + return IGeofenceProvider.Stub.asInterface(mServiceWatcher.getBinder()); + } + + private void bindHardwareGeofence() { + mContext.bindServiceAsUser(new Intent(mContext, GeofenceHardwareService.class), + mServiceConnection, Context.BIND_AUTO_CREATE, UserHandle.OWNER); + } + + private ServiceConnection mServiceConnection = new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + mGeofenceHardware = IGeofenceHardware.Stub.asInterface(service); + mHandler.sendEmptyMessage(GEOFENCE_HARDWARE_CONNECTED); + } + + @Override + public void onServiceDisconnected(ComponentName name) { + mGeofenceHardware = null; + mHandler.sendEmptyMessage(GEOFENCE_HARDWARE_DISCONNECTED); + } + }; + + private void setGeofenceHardwareInProvider() { + try { + getGeofenceProviderService().setGeofenceHardware(mGeofenceHardware); + } catch (RemoteException e) { + Log.e(TAG, "Remote Exception: setGeofenceHardwareInProvider: " + e); + } + } + + private void setGpsGeofence() { + try { + mGeofenceHardware.setGpsGeofenceHardware(mGpsGeofenceHardware); + } catch (RemoteException e) { + Log.e(TAG, "Error while connecting to GeofenceHardwareService"); + } + } + + + // This needs to be reworked, when more services get added, + // Might need a state machine or add a framework utility class, + private Handler mHandler = new Handler() { + private boolean mGeofenceHardwareConnected = false; + private boolean mGeofenceProviderConnected = false; + + + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case GEOFENCE_PROVIDER_CONNECTED: + mGeofenceProviderConnected = true; + if (mGeofenceHardwareConnected) { + setGeofenceHardwareInProvider(); + } + break; + case GEOFENCE_HARDWARE_CONNECTED: + setGpsGeofence(); + mGeofenceHardwareConnected = true; + if (mGeofenceProviderConnected) { + setGeofenceHardwareInProvider(); + } + break; + case GEOFENCE_HARDWARE_DISCONNECTED: + mGeofenceHardwareConnected = false; + setGeofenceHardwareInProvider(); + break; + } + } + }; +} diff --git a/services/java/com/android/server/location/GpsLocationProvider.java b/services/java/com/android/server/location/GpsLocationProvider.java index 3552b6a..1ebff67 100644 --- a/services/java/com/android/server/location/GpsLocationProvider.java +++ b/services/java/com/android/server/location/GpsLocationProvider.java @@ -24,7 +24,10 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.database.Cursor; +import android.hardware.location.GeofenceHardwareImpl; +import android.hardware.location.IGeofenceHardware; import android.location.Criteria; +import android.location.IGpsGeofenceHardware; import android.location.IGpsStatusListener; import android.location.IGpsStatusProvider; import android.location.ILocationManager; @@ -314,6 +317,8 @@ public class GpsLocationProvider implements LocationProviderInterface { // only modified on handler thread private WorkSource mClientSource = new WorkSource(); + private GeofenceHardwareImpl mGeofenceHardwareImpl; + private final IGpsStatusProvider mGpsStatusProvider = new IGpsStatusProvider.Stub() { @Override public void addGpsStatusListener(IGpsStatusListener listener) throws RemoteException { @@ -367,6 +372,10 @@ public class GpsLocationProvider implements LocationProviderInterface { return mGpsStatusProvider; } + public IGpsGeofenceHardware getGpsGeofenceProxy() { + return mGpsGeofenceBinder; + } + private final BroadcastReceiver mBroadcastReciever = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); @@ -918,6 +927,31 @@ public class GpsLocationProvider implements LocationProviderInterface { return result; } + private IGpsGeofenceHardware mGpsGeofenceBinder = new IGpsGeofenceHardware.Stub() { + public boolean isHardwareGeofenceSupported() { + return native_is_geofence_supported(); + } + + public boolean addCircularHardwareGeofence(int geofenceId, double latitude, + double longitude, double radius, int lastTransition, int monitorTransitions, + int notificationResponsiveness, int unknownTimer) { + return native_add_geofence(geofenceId, latitude, longitude, radius, + lastTransition, monitorTransitions, notificationResponsiveness, unknownTimer); + } + + public boolean removeHardwareGeofence(int geofenceId) { + return native_remove_geofence(geofenceId); + } + + public boolean pauseHardwareGeofence(int geofenceId) { + return native_pause_geofence(geofenceId); + } + + public boolean resumeHardwareGeofence(int geofenceId, int monitorTransition) { + return native_resume_geofence(geofenceId, monitorTransition); + } + }; + private boolean deleteAidingData(Bundle extras) { int flags; @@ -1017,6 +1051,7 @@ public class GpsLocationProvider implements LocationProviderInterface { return ((mEngineCapabilities & capability) != 0); } + /** * called from native code to update our position. */ @@ -1320,6 +1355,73 @@ public class GpsLocationProvider implements LocationProviderInterface { sendMessage(DOWNLOAD_XTRA_DATA, 0, null); } + /** + * Called from native to report GPS Geofence transition + * All geofence callbacks are called on the same thread + */ + private void reportGeofenceTransition(int geofenceId, int flags, double latitude, + double longitude, double altitude, float speed, float bearing, float accuracy, + long timestamp, int transition, long transitionTimestamp) { + if (mGeofenceHardwareImpl == null) { + mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); + } + mGeofenceHardwareImpl.reportGpsGeofenceTransition(geofenceId, flags, latitude, longitude, + altitude, speed, bearing, accuracy, timestamp, transition, transitionTimestamp); + } + + /** + * called from native code to report GPS status change. + */ + private void reportGeofenceStatus(int status, int flags, double latitude, + double longitude, double altitude, float speed, float bearing, float accuracy, + long timestamp) { + if (mGeofenceHardwareImpl == null) { + mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); + } + mGeofenceHardwareImpl.reportGpsGeofenceStatus(status, flags, latitude, longitude, altitude, + speed, bearing, accuracy, timestamp); + } + + /** + * called from native code - Geofence Add callback + */ + private void reportGeofenceAddStatus(int geofenceId, int status) { + if (mGeofenceHardwareImpl == null) { + mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); + } + mGeofenceHardwareImpl.reportGpsGeofenceAddStatus(geofenceId, status); + } + + /** + * called from native code - Geofence Remove callback + */ + private void reportGeofenceRemoveStatus(int geofenceId, int status) { + if (mGeofenceHardwareImpl == null) { + mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); + } + mGeofenceHardwareImpl.reportGpsGeofenceRemoveStatus(geofenceId, status); + } + + /** + * called from native code - Geofence Pause callback + */ + private void reportGeofencePauseStatus(int geofenceId, int status) { + if (mGeofenceHardwareImpl == null) { + mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); + } + mGeofenceHardwareImpl.reportGpsGeofencePauseStatus(geofenceId, status); + } + + /** + * called from native code - Geofence Resume callback + */ + private void reportGeofenceResumeStatus(int geofenceId, int status) { + if (mGeofenceHardwareImpl == null) { + mGeofenceHardwareImpl = GeofenceHardwareImpl.getInstance(mContext); + } + mGeofenceHardwareImpl.reportGpsGeofenceResumeStatus(geofenceId, status); + } + //============================================================= // NI Client support //============================================================= @@ -1650,4 +1752,13 @@ public class GpsLocationProvider implements LocationProviderInterface { private native void native_update_network_state(boolean connected, int type, boolean roaming, boolean available, String extraInfo, String defaultAPN); + + // Hardware Geofence support. + private static native boolean native_is_geofence_supported(); + private static native boolean native_add_geofence(int geofenceId, double latitude, + double longitude, double radius, int lastTransition,int monitorTransitions, + int notificationResponsivenes, int unknownTimer); + private static native boolean native_remove_geofence(int geofenceId); + private static native boolean native_resume_geofence(int geofenceId, int transitions); + private static native boolean native_pause_geofence(int geofenceId); } diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java index cc9b785..154c4e8 100644 --- a/services/java/com/android/server/pm/PackageManagerService.java +++ b/services/java/com/android/server/pm/PackageManagerService.java @@ -8249,6 +8249,24 @@ public class PackageManagerService extends IPackageManager.Stub { updatePermissionsLPw(newPackage.packageName, newPackage, UPDATE_PERMISSIONS_REPLACE_PKG | (newPackage.permissions.size() > 0 ? UPDATE_PERMISSIONS_ALL : 0)); + // For system-bundled packages, we assume that installing an upgraded version + // of the package implies that the user actually wants to run that new code, + // so we enable the package. + if (isSystemApp(newPackage)) { + // NB: implicit assumption that system package upgrades apply to all users + if (DEBUG_INSTALL) { + Slog.d(TAG, "Implicitly enabling system package on upgrade: " + pkgName); + } + PackageSetting ps = mSettings.mPackages.get(pkgName); + if (ps != null) { + if (res.origUsers != null) { + for (int userHandle : res.origUsers) { + ps.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, + userHandle, installerPackageName); + } + } + } + } res.name = pkgName; res.uid = newPackage.applicationInfo.uid; res.pkg = newPackage; diff --git a/services/java/com/android/server/pm/UserManagerService.java b/services/java/com/android/server/pm/UserManagerService.java index aa1b2ff..3ef9370 100644 --- a/services/java/com/android/server/pm/UserManagerService.java +++ b/services/java/com/android/server/pm/UserManagerService.java @@ -963,7 +963,7 @@ public class UserManagerService extends IUserManager.Stub { @Override public List<RestrictionEntry> getApplicationRestrictions(String packageName, int userId) { if (UserHandle.getCallingUserId() != userId - || Binder.getCallingUid() != getUidForPackage(packageName)) { + || !UserHandle.isSameApp(Binder.getCallingUid(), getUidForPackage(packageName))) { checkManageUsersPermission("Only system can get restrictions for other users/apps"); } synchronized (mPackagesLock) { @@ -976,7 +976,7 @@ public class UserManagerService extends IUserManager.Stub { public void setApplicationRestrictions(String packageName, List<RestrictionEntry> entries, int userId) { if (UserHandle.getCallingUserId() != userId - || Binder.getCallingUid() != getUidForPackage(packageName)) { + || !UserHandle.isSameApp(Binder.getCallingUid(), getUidForPackage(packageName))) { checkManageUsersPermission("Only system can set restrictions for other users/apps"); } synchronized (mPackagesLock) { @@ -986,11 +986,14 @@ public class UserManagerService extends IUserManager.Stub { } private int getUidForPackage(String packageName) { + long ident = Binder.clearCallingIdentity(); try { return mContext.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES).uid; } catch (NameNotFoundException nnfe) { return -1; + } finally { + Binder.restoreCallingIdentity(ident); } } diff --git a/services/java/com/android/server/power/PowerManagerService.java b/services/java/com/android/server/power/PowerManagerService.java index 2652739..1203e02 100644 --- a/services/java/com/android/server/power/PowerManagerService.java +++ b/services/java/com/android/server/power/PowerManagerService.java @@ -432,7 +432,7 @@ public final class PowerManagerService extends IPowerManager.Stub mScreenBrightnessSettingMaximum = pm.getMaximumScreenBrightnessSetting(); mScreenBrightnessSettingDefault = pm.getDefaultScreenBrightnessSetting(); - SensorManager sensorManager = new SystemSensorManager(mHandler.getLooper()); + SensorManager sensorManager = new SystemSensorManager(mContext, mHandler.getLooper()); // The notifier runs on the system server's main looper so as not to interfere // with the animations and other critical functions of the power manager. diff --git a/services/java/com/android/server/wm/AppWindowAnimator.java b/services/java/com/android/server/wm/AppWindowAnimator.java index 297324b..6293dc6 100644 --- a/services/java/com/android/server/wm/AppWindowAnimator.java +++ b/services/java/com/android/server/wm/AppWindowAnimator.java @@ -4,6 +4,7 @@ package com.android.server.wm; import android.graphics.Matrix; import android.util.Slog; +import android.util.TimeUtils; import android.view.Display; import android.view.Surface; import android.view.SurfaceControl; @@ -30,6 +31,11 @@ public class AppWindowAnimator { // Protect with mAnimator. boolean freezingScreen; + /** + * How long we last kept the screen frozen. + */ + int lastFreezeDuration; + // Offset to the window of all layers in the token, for use by // AppWindowToken animations. int animLayerAdjustment; @@ -287,6 +293,10 @@ public class AppWindowAnimator { pw.print(prefix); pw.print("freezingScreen="); pw.print(freezingScreen); pw.print(" allDrawn="); pw.print(allDrawn); pw.print(" animLayerAdjustment="); pw.println(animLayerAdjustment); + if (lastFreezeDuration != 0) { + pw.print(prefix); pw.print("lastFreezeDuration="); + TimeUtils.formatDuration(lastFreezeDuration, pw); pw.println(); + } if (animating || animation != null) { pw.print(prefix); pw.print("animating="); pw.println(animating); pw.print(prefix); pw.print("animation="); pw.println(animation); diff --git a/services/java/com/android/server/wm/WindowAnimator.java b/services/java/com/android/server/wm/WindowAnimator.java index 3964782..054a075 100644 --- a/services/java/com/android/server/wm/WindowAnimator.java +++ b/services/java/com/android/server/wm/WindowAnimator.java @@ -70,6 +70,7 @@ public class WindowAnimator { int mAboveUniverseLayer = 0; int mBulkUpdateParams = 0; + Object mLastWindowFreezeSource; SparseArray<DisplayContentsAnimator> mDisplayContentsAnimators = new SparseArray<WindowAnimator.DisplayContentsAnimator>(); diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java index af603fd..1d1fda5 100644 --- a/services/java/com/android/server/wm/WindowManagerService.java +++ b/services/java/com/android/server/wm/WindowManagerService.java @@ -43,6 +43,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER; import android.app.AppOpsManager; +import android.util.TimeUtils; import android.view.IWindowId; import com.android.internal.app.IBatteryStats; import com.android.internal.policy.PolicyManager; @@ -464,6 +465,9 @@ public class WindowManagerService extends IWindowManager.Stub boolean mTraversalScheduled = false; boolean mDisplayFrozen = false; + long mDisplayFreezeTime = 0; + int mLastDisplayFreezeDuration = 0; + Object mLastFinishedFreezeSource = null; boolean mWaitingForConfig = false; boolean mWindowsFreezingScreen = false; boolean mClientFreezingScreen = false; @@ -582,6 +586,7 @@ public class WindowManagerService extends IWindowManager.Stub boolean mWallpaperForceHidingChanged = false; boolean mWallpaperMayChange = false; boolean mOrientationChangeComplete = true; + Object mLastWindowFreezeSource = null; private Session mHoldScreen = null; private boolean mObscured = false; boolean mDimming = false; @@ -3590,7 +3595,10 @@ public class WindowManagerService extends IWindowManager.Stub synchronized(mWindowMap) { mCurConfiguration = new Configuration(config); - mWaitingForConfig = false; + if (mWaitingForConfig) { + mWaitingForConfig = false; + mLastFinishedFreezeSource = "new-config"; + } performLayoutAndPlaceSurfacesLocked(); } } @@ -4209,6 +4217,7 @@ public class WindowManagerService extends IWindowManager.Stub w.mOrientationChanging = true; mInnerFields.mOrientationChangeComplete = false; } + w.mLastFreezeDuration = 0; unfrozeWindows = true; w.mDisplayContent.layoutNeeded = true; } @@ -4216,7 +4225,10 @@ public class WindowManagerService extends IWindowManager.Stub if (force || unfrozeWindows) { if (DEBUG_ORIENTATION) Slog.v(TAG, "No longer freezing: " + wtoken); wtoken.mAppAnimator.freezingScreen = false; + wtoken.mAppAnimator.lastFreezeDuration = (int)(SystemClock.elapsedRealtime() + - mDisplayFreezeTime); mAppsFreezingScreen--; + mLastFinishedFreezeSource = wtoken; } if (unfreezeSurfaceNow) { if (unfrozeWindows) { @@ -4242,6 +4254,7 @@ public class WindowManagerService extends IWindowManager.Stub if (!wtoken.hiddenRequested) { if (!wtoken.mAppAnimator.freezingScreen) { wtoken.mAppAnimator.freezingScreen = true; + wtoken.mAppAnimator.lastFreezeDuration = 0; mAppsFreezingScreen++; if (mAppsFreezingScreen == 1) { startFreezingDisplayLocked(false, 0, 0); @@ -4750,6 +4763,7 @@ public class WindowManagerService extends IWindowManager.Stub synchronized(mWindowMap) { if (mClientFreezingScreen) { mClientFreezingScreen = false; + mLastFinishedFreezeSource = "client"; final long origId = Binder.clearCallingIdentity(); try { stopFreezingDisplayLocked(); @@ -5742,6 +5756,7 @@ public class WindowManagerService extends IWindowManager.Stub w.mOrientationChanging = true; mInnerFields.mOrientationChangeComplete = false; } + w.mLastFreezeDuration = 0; } for (int i=mRotationWatchers.size()-1; i>=0; i--) { @@ -6240,6 +6255,7 @@ public class WindowManagerService extends IWindowManager.Stub if (config == null && mWaitingForConfig) { // Nothing changed but we are waiting for something... stop that! mWaitingForConfig = false; + mLastFinishedFreezeSource = "new-config"; performLayoutAndPlaceSurfacesLocked(); } return config; @@ -7036,6 +7052,8 @@ public class WindowManagerService extends IWindowManager.Stub WindowState w = windows.get(i); if (w.mOrientationChanging) { w.mOrientationChanging = false; + w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() + - mDisplayFreezeTime); Slog.w(TAG, "Force clearing orientation change: " + w); } } @@ -7112,6 +7130,7 @@ public class WindowManagerService extends IWindowManager.Stub synchronized (mWindowMap) { if (mClientFreezingScreen) { mClientFreezingScreen = false; + mLastFinishedFreezeSource = "client-timeout"; stopFreezingDisplayLocked(); } } @@ -8029,6 +8048,7 @@ public class WindowManagerService extends IWindowManager.Stub if (DEBUG_ORIENTATION) Slog.v(TAG, "Changing surface while display frozen: " + w); w.mOrientationChanging = true; + w.mLastFreezeDuration = 0; mInnerFields.mOrientationChangeComplete = false; if (!mWindowsFreezingScreen) { mWindowsFreezingScreen = true; @@ -8417,6 +8437,8 @@ public class WindowManagerService extends IWindowManager.Stub "Orientation not waiting for draw in " + w + ", surface " + winAnimator.mSurfaceControl); w.mOrientationChanging = false; + w.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() + - mDisplayFreezeTime); } } } @@ -8930,6 +8952,8 @@ public class WindowManagerService extends IWindowManager.Stub winAnimator.mSurfaceResized = false; } catch (RemoteException e) { win.mOrientationChanging = false; + win.mLastFreezeDuration = (int)(SystemClock.elapsedRealtime() + - mDisplayFreezeTime); } mResizingWindows.remove(i); } @@ -8940,6 +8964,7 @@ public class WindowManagerService extends IWindowManager.Stub if (mInnerFields.mOrientationChangeComplete) { if (mWindowsFreezingScreen) { mWindowsFreezingScreen = false; + mLastFinishedFreezeSource = mInnerFields.mLastWindowFreezeSource; mH.removeMessages(H.WINDOW_FREEZE_TIMEOUT); } stopFreezingDisplayLocked(); @@ -9226,6 +9251,7 @@ public class WindowManagerService extends IWindowManager.Stub mInnerFields.mOrientationChangeComplete = false; } else { mInnerFields.mOrientationChangeComplete = true; + mInnerFields.mLastWindowFreezeSource = mAnimator.mLastWindowFreezeSource; if (mWindowsFreezingScreen) { doRequest = true; } @@ -9498,6 +9524,8 @@ public class WindowManagerService extends IWindowManager.Stub mScreenFrozenLock.acquire(); mDisplayFrozen = true; + mDisplayFreezeTime = SystemClock.elapsedRealtime(); + mLastFinishedFreezeSource = null; mInputMonitor.freezeInputDispatchingLw(); @@ -9552,6 +9580,15 @@ public class WindowManagerService extends IWindowManager.Stub } mDisplayFrozen = false; + mLastDisplayFreezeDuration = (int)(SystemClock.elapsedRealtime() - mDisplayFreezeTime); + StringBuilder sb = new StringBuilder(128); + sb.append("Screen frozen for "); + TimeUtils.formatDuration(mLastDisplayFreezeDuration, sb); + if (mLastFinishedFreezeSource != null) { + sb.append(" due to "); + sb.append(mLastFinishedFreezeSource); + } + Slog.i(TAG, sb.toString()); mH.removeMessages(H.APP_FREEZE_TIMEOUT); mH.removeMessages(H.CLIENT_FREEZE_TIMEOUT); if (PROFILE_ORIENTATION) { @@ -10076,6 +10113,13 @@ public class WindowManagerService extends IWindowManager.Stub } pw.print(" mInTouchMode="); pw.print(mInTouchMode); pw.print(" mLayoutSeq="); pw.println(mLayoutSeq); + pw.print(" mLastDisplayFreezeDuration="); + TimeUtils.formatDuration(mLastDisplayFreezeDuration, pw); + if ( mLastFinishedFreezeSource != null) { + pw.print(" due to "); + pw.print(mLastFinishedFreezeSource); + } + pw.println(); if (dumpAll) { pw.print(" mSystemDecorRect="); pw.print(mSystemDecorRect.toShortString()); pw.print(" mSystemDecorLayer="); pw.print(mSystemDecorLayer); diff --git a/services/java/com/android/server/wm/WindowState.java b/services/java/com/android/server/wm/WindowState.java index 506fcec..ca060f4 100644 --- a/services/java/com/android/server/wm/WindowState.java +++ b/services/java/com/android/server/wm/WindowState.java @@ -26,6 +26,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; import android.app.AppOpsManager; import android.os.RemoteCallbackList; +import android.util.TimeUtils; import android.view.IWindowFocusObserver; import android.view.IWindowId; import com.android.server.input.InputWindowHandle; @@ -266,6 +267,11 @@ final class WindowState implements WindowManagerPolicy.WindowState { */ boolean mOrientationChanging; + /** + * How long we last kept the screen frozen. + */ + int mLastFreezeDuration; + /** Is this window now (or just being) removed? */ boolean mRemoved; @@ -1387,6 +1393,10 @@ final class WindowState implements WindowManagerPolicy.WindowState { pw.print(" mAppFreezing="); pw.print(mAppFreezing); pw.print(" mTurnOnScreen="); pw.println(mTurnOnScreen); } + if (mLastFreezeDuration != 0) { + pw.print(prefix); pw.print("mLastFreezeDuration="); + TimeUtils.formatDuration(mLastFreezeDuration, pw); pw.println(); + } if (mHScale != 1 || mVScale != 1) { pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); pw.print(" mVScale="); pw.println(mVScale); diff --git a/services/java/com/android/server/wm/WindowStateAnimator.java b/services/java/com/android/server/wm/WindowStateAnimator.java index 3a9f7cb..c07174b 100644 --- a/services/java/com/android/server/wm/WindowStateAnimator.java +++ b/services/java/com/android/server/wm/WindowStateAnimator.java @@ -505,20 +505,20 @@ class WindowStateAnimator { public void setAlpha(float alpha) { super.setAlpha(alpha); if (alpha != mSurfaceTraceAlpha) { + mSurfaceTraceAlpha = alpha; Slog.v(SURFACE_TAG, "setAlpha: " + this + ". Called by " + Debug.getCallers(3)); } - mSurfaceTraceAlpha = alpha; } @Override public void setLayer(int zorder) { super.setLayer(zorder); if (zorder != mLayer) { + mLayer = zorder; Slog.v(SURFACE_TAG, "setLayer: " + this + ". Called by " + Debug.getCallers(3)); } - mLayer = zorder; sSurfaces.remove(this); int i; @@ -535,20 +535,20 @@ class WindowStateAnimator { public void setPosition(float x, float y) { super.setPosition(x, y); if (x != mPosition.x || y != mPosition.y) { + mPosition.set(x, y); Slog.v(SURFACE_TAG, "setPosition: " + this + ". Called by " + Debug.getCallers(3)); } - mPosition.set(x, y); } @Override public void setSize(int w, int h) { super.setSize(w, h); if (w != mSize.x || h != mSize.y) { + mSize.set(w, h); Slog.v(SURFACE_TAG, "setSize: " + this + ". Called by " + Debug.getCallers(3)); } - mSize.set(w, h); } @Override @@ -556,10 +556,10 @@ class WindowStateAnimator { super.setWindowCrop(crop); if (crop != null) { if (!crop.equals(mWindowCrop)) { + mWindowCrop.set(crop); Slog.v(SURFACE_TAG, "setWindowCrop: " + this + ". Called by " + Debug.getCallers(3)); } - mWindowCrop.set(crop); } } @@ -567,28 +567,28 @@ class WindowStateAnimator { public void setLayerStack(int layerStack) { super.setLayerStack(layerStack); if (layerStack != mLayerStack) { + mLayerStack = layerStack; Slog.v(SURFACE_TAG, "setLayerStack: " + this + ". Called by " + Debug.getCallers(3)); } - mLayerStack = layerStack; } @Override public void hide() { super.hide(); if (mShown) { + mShown = false; Slog.v(SURFACE_TAG, "hide: " + this + ". Called by " + Debug.getCallers(3)); } - mShown = false; } @Override public void show() { super.show(); if (!mShown) { + mShown = true; Slog.v(SURFACE_TAG, "show: " + this + ". Called by " + Debug.getCallers(3)); } - mShown = true; } @Override @@ -1307,6 +1307,7 @@ class WindowStateAnimator { if (w.mOrientationChanging) { if (!w.isDrawnLw()) { mAnimator.mBulkUpdateParams &= ~SET_ORIENTATION_CHANGE_COMPLETE; + mAnimator.mLastWindowFreezeSource = w; if (DEBUG_ORIENTATION) Slog.v(TAG, "Orientation continue waiting for draw in " + w); } else { |