use of android.content.Context in project platform_frameworks_base by android.
the class DreamManagerService method onBootPhase.
@Override
public void onBootPhase(int phase) {
if (phase == SystemService.PHASE_THIRD_PARTY_APPS_CAN_START) {
if (Build.IS_DEBUGGABLE) {
SystemProperties.addChangeCallback(mSystemPropertiesChanged);
}
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
writePulseGestureEnabled();
synchronized (mLock) {
stopDreamLocked(false);
}
}
}, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mHandler);
mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(Settings.Secure.DOZE_ENABLED), false, mDozeEnabledObserver, UserHandle.USER_ALL);
writePulseGestureEnabled();
}
}
use of android.content.Context in project platform_frameworks_base by android.
the class MediaRouterService method systemRunning.
public void systemRunning() {
IntentFilter filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_USER_SWITCHED)) {
switchUser();
}
}
}, filter);
switchUser();
}
use of android.content.Context in project platform_frameworks_base by android.
the class MediaSessionRecord method updateCallingPackage.
private void updateCallingPackage(int uid, String packageName) {
if (uid == UID_NOT_SET) {
uid = Binder.getCallingUid();
}
synchronized (mLock) {
if (mCallingUid == UID_NOT_SET || mCallingUid != uid) {
mCallingUid = uid;
mCallingPackage = packageName;
if (mCallingPackage != null) {
return;
}
Context context = mService.getContext();
if (context == null) {
return;
}
String[] packages = context.getPackageManager().getPackagesForUid(uid);
if (packages != null && packages.length > 0) {
mCallingPackage = packages[0];
}
}
}
}
use of android.content.Context in project platform_frameworks_base by android.
the class UserManagerService method finishRemoveUser.
void finishRemoveUser(final int userHandle) {
if (DBG)
Slog.i(LOG_TAG, "finishRemoveUser " + userHandle);
// Let other services shutdown any activity and clean up their state before completely
// wiping the user's system directory and removing from the user list
long ident = Binder.clearCallingIdentity();
try {
Intent addedIntent = new Intent(Intent.ACTION_USER_REMOVED);
addedIntent.putExtra(Intent.EXTRA_USER_HANDLE, userHandle);
mContext.sendOrderedBroadcastAsUser(addedIntent, UserHandle.ALL, android.Manifest.permission.MANAGE_USERS, new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (DBG) {
Slog.i(LOG_TAG, "USER_REMOVED broadcast sent, cleaning up user data " + userHandle);
}
new Thread() {
@Override
public void run() {
// Clean up any ActivityManager state
LocalServices.getService(ActivityManagerInternal.class).onUserRemoved(userHandle);
removeUserState(userHandle);
}
}.start();
}
}, null, Activity.RESULT_OK, null, null);
} finally {
Binder.restoreCallingIdentity(ident);
}
}
use of android.content.Context in project platform_frameworks_base by android.
the class NetworkPolicyManagerServiceTest method callSystemReady.
@Before
public void callSystemReady() throws Exception {
MockitoAnnotations.initMocks(this);
final Context context = InstrumentationRegistry.getContext();
setCurrentTimeMillis(TEST_START);
// intercept various broadcasts, and pretend that uids have packages
mServiceContext = new BroadcastInterceptingContext(context) {
@Override
public PackageManager getPackageManager() {
return mPackageManager;
}
@Override
public void startActivity(Intent intent) {
// ignored
}
};
mPolicyDir = context.getFilesDir();
if (mPolicyDir.exists()) {
IoUtils.deleteContents(mPolicyDir);
}
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
mUidObserver = (IUidObserver) invocation.getArguments()[0];
Log.d(TAG, "set mUidObserver to " + mUidObserver);
return null;
}
}).when(mActivityManager).registerUidObserver(any(), anyInt());
mService = new NetworkPolicyManagerService(mServiceContext, mActivityManager, mStatsService, mNetworkManager, mTime, mPolicyDir, true);
mService.bindConnectivityManager(mConnManager);
mService.bindNotificationManager(mNotifManager);
mPolicyListener = new NetworkPolicyListenerAnswer(mService);
// Sets some common expectations.
when(mPackageManager.getPackageInfo(anyString(), anyInt())).thenAnswer(new Answer<PackageInfo>() {
@Override
public PackageInfo answer(InvocationOnMock invocation) throws Throwable {
final String packageName = (String) invocation.getArguments()[0];
final PackageInfo info = new PackageInfo();
final Signature signature;
if ("android".equals(packageName)) {
signature = new Signature("F00D");
} else {
signature = new Signature("DEAD");
}
info.signatures = new Signature[] { signature };
return info;
}
});
when(mPackageManager.getApplicationInfoAsUser(anyString(), anyInt(), anyInt())).thenReturn(new ApplicationInfo());
when(mPackageManager.getPackagesForUid(UID_A)).thenReturn(new String[] { PKG_NAME_A });
when(mNetworkManager.isBandwidthControlEnabled()).thenReturn(true);
expectCurrentTime();
// Prepare NPMS.
mService.systemReady();
// catch INetworkManagementEventObserver during systemReady()
ArgumentCaptor<INetworkManagementEventObserver> networkObserver = ArgumentCaptor.forClass(INetworkManagementEventObserver.class);
verify(mNetworkManager).registerObserver(networkObserver.capture());
mNetworkObserver = networkObserver.getValue();
}
Aggregations