Search in sources :

Example 76 with Context

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();
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 77 with Context

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();
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 78 with Context

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];
            }
        }
    }
}
Also used : Context(android.content.Context)

Example 79 with Context

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);
    }
}
Also used : Context(android.content.Context) ActivityManagerInternal(android.app.ActivityManagerInternal) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 80 with Context

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();
}
Also used : BroadcastInterceptingContext(com.android.internal.util.test.BroadcastInterceptingContext) Context(android.content.Context) PackageInfo(android.content.pm.PackageInfo) BroadcastInterceptingContext(com.android.internal.util.test.BroadcastInterceptingContext) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) Matchers.anyString(org.mockito.Matchers.anyString) IUidObserver(android.app.IUidObserver) NetworkPolicyManagerService(com.android.server.net.NetworkPolicyManagerService) PackageManager(android.content.pm.PackageManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Signature(android.content.pm.Signature) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) Before(org.junit.Before)

Aggregations

Context (android.content.Context)3233 Intent (android.content.Intent)676 View (android.view.View)400 Test (org.junit.Test)346 BroadcastReceiver (android.content.BroadcastReceiver)338 IntentFilter (android.content.IntentFilter)301 TextView (android.widget.TextView)258 Resources (android.content.res.Resources)226 PendingIntent (android.app.PendingIntent)188 PackageManager (android.content.pm.PackageManager)164 File (java.io.File)156 IOException (java.io.IOException)150 LayoutInflater (android.view.LayoutInflater)139 ImageView (android.widget.ImageView)135 Drawable (android.graphics.drawable.Drawable)128 Uri (android.net.Uri)115 RemoteException (android.os.RemoteException)102 ArrayList (java.util.ArrayList)102 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)101 Bundle (android.os.Bundle)95