use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.
the class ActivityManagerService method finishBooting.
final void finishBooting() {
synchronized (this) {
if (!mBootAnimationComplete) {
mCallFinishBooting = true;
return;
}
mCallFinishBooting = false;
}
ArraySet<String> completedIsas = new ArraySet<String>();
for (String abi : Build.SUPPORTED_ABIS) {
Process.establishZygoteConnectionForAbi(abi);
final String instructionSet = VMRuntime.getInstructionSet(abi);
if (!completedIsas.contains(instructionSet)) {
try {
mInstaller.markBootComplete(VMRuntime.getInstructionSet(abi));
} catch (InstallerException e) {
Slog.w(TAG, "Unable to mark boot complete for abi: " + abi + " (" + e.getMessage() + ")");
}
completedIsas.add(instructionSet);
}
}
IntentFilter pkgFilter = new IntentFilter();
pkgFilter.addAction(Intent.ACTION_QUERY_PACKAGE_RESTART);
pkgFilter.addDataScheme("package");
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String[] pkgs = intent.getStringArrayExtra(Intent.EXTRA_PACKAGES);
if (pkgs != null) {
for (String pkg : pkgs) {
synchronized (ActivityManagerService.this) {
if (forceStopPackageLocked(pkg, -1, false, false, false, false, false, 0, "query restart")) {
setResultCode(Activity.RESULT_OK);
return;
}
}
}
}
}
}, pkgFilter);
IntentFilter dumpheapFilter = new IntentFilter();
dumpheapFilter.addAction(DumpHeapActivity.ACTION_DELETE_DUMPHEAP);
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getBooleanExtra(DumpHeapActivity.EXTRA_DELAY_DELETE, false)) {
mHandler.sendEmptyMessageDelayed(POST_DUMP_HEAP_NOTIFICATION_MSG, 5 * 60 * 1000);
} else {
mHandler.sendEmptyMessage(POST_DUMP_HEAP_NOTIFICATION_MSG);
}
}
}, dumpheapFilter);
// Let system services know.
mSystemServiceManager.startBootPhase(SystemService.PHASE_BOOT_COMPLETED);
synchronized (this) {
// Ensure that any processes we had put on hold are now started
// up.
final int NP = mProcessesOnHold.size();
if (NP > 0) {
ArrayList<ProcessRecord> procs = new ArrayList<ProcessRecord>(mProcessesOnHold);
for (int ip = 0; ip < NP; ip++) {
if (DEBUG_PROCESSES)
Slog.v(TAG_PROCESSES, "Starting process on hold: " + procs.get(ip));
startProcessLocked(procs.get(ip), "on-hold", null);
}
}
if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
// Start looking for apps that are abusing wake locks.
Message nmsg = mHandler.obtainMessage(CHECK_EXCESSIVE_WAKE_LOCKS_MSG);
mHandler.sendMessageDelayed(nmsg, POWER_CHECK_DELAY);
// Tell anyone interested that we are done booting!
SystemProperties.set("sys.boot_completed", "1");
// And trigger dev.bootcomplete if we are not showing encryption progress
if (!"trigger_restart_min_framework".equals(SystemProperties.get("vold.decrypt")) || "".equals(SystemProperties.get("vold.encrypt_progress"))) {
SystemProperties.set("dev.bootcomplete", "1");
}
mUserController.sendBootCompletedLocked(new IIntentReceiver.Stub() {
@Override
public void performReceive(Intent intent, int resultCode, String data, Bundle extras, boolean ordered, boolean sticky, int sendingUser) {
synchronized (ActivityManagerService.this) {
requestPssAllProcsLocked(SystemClock.uptimeMillis(), true, false);
}
}
});
scheduleStartProfilesLocked();
}
}
}
use of android.content.BroadcastReceiver in project mobile-center-sdk-android by Microsoft.
the class NetworkStateHelperTest method listenNetwork.
@Test
public void listenNetwork() {
Context context = mock(Context.class);
ConnectivityManager connectivityManager = mock(ConnectivityManager.class);
final AtomicReference<BroadcastReceiver> receiverRef = new AtomicReference<>();
when(context.getApplicationContext()).thenReturn(context);
when(context.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(connectivityManager);
when(context.registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class))).then(new Answer<Intent>() {
@Override
public Intent answer(InvocationOnMock invocation) throws Throwable {
BroadcastReceiver receiver = (BroadcastReceiver) invocation.getArguments()[0];
IntentFilter filter = (IntentFilter) invocation.getArguments()[1];
assertNotNull(receiver);
assertNotNull(filter);
receiverRef.set(receiver);
return mock(Intent.class);
}
});
NetworkStateHelper helper = new NetworkStateHelper(context);
NetworkStateHelper.Listener listener = mock(NetworkStateHelper.Listener.class);
helper.addListener(listener);
/* Initial state is down, if state does not change, no callback. */
BroadcastReceiver receiver = receiverRef.get();
receiver.onReceive(context, mock(Intent.class));
verify(listener, never()).onNetworkStateUpdated(anyBoolean());
/* Change state to up. */
NetworkInfo networkInfo = mock(NetworkInfo.class);
when(networkInfo.getState()).thenReturn(NetworkInfo.State.CONNECTED);
when(networkInfo.getTypeName()).thenReturn("MOBILE");
when(networkInfo.getSubtypeName()).thenReturn("EDGE");
when(connectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo);
receiver.onReceive(context, mock(Intent.class));
verify(listener).onNetworkStateUpdated(true);
verify(listener, never()).onNetworkStateUpdated(false);
/* Change to WIFI. */
helper.removeListener(listener);
NetworkStateHelper.Listener listener2 = mock(NetworkStateHelper.Listener.class);
helper.addListener(listener2);
when(networkInfo.getTypeName()).thenReturn("WIFI");
when(networkInfo.getSubtypeName()).thenReturn(null);
receiver.onReceive(context, mock(Intent.class));
verify(listener2).onNetworkStateUpdated(false);
verify(listener2).onNetworkStateUpdated(true);
/* Duplicate WIFI callback. */
receiver.onReceive(context, mock(Intent.class));
verifyNoMoreInteractions(listener2);
/* But then WIFI is disconnected. */
helper.removeListener(listener2);
NetworkStateHelper.Listener listener3 = mock(NetworkStateHelper.Listener.class);
helper.addListener(listener3);
when(networkInfo.getState()).thenReturn(NetworkInfo.State.DISCONNECTED);
receiver.onReceive(context, mock(Intent.class));
verify(listener3).onNetworkStateUpdated(false);
/* Close and verify interactions. */
helper.close();
verify(context).unregisterReceiver(receiver);
verifyNoMoreInteractions(listener);
verifyNoMoreInteractions(listener2);
verifyNoMoreInteractions(listener3);
}
use of android.content.BroadcastReceiver in project android_frameworks_base by AOSPA.
the class SettingsProvider method registerBroadcastReceivers.
private void registerBroadcastReceivers() {
IntentFilter userFilter = new IntentFilter();
userFilter.addAction(Intent.ACTION_USER_REMOVED);
userFilter.addAction(Intent.ACTION_USER_STOPPED);
getContext().registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_SYSTEM);
switch(intent.getAction()) {
case Intent.ACTION_USER_REMOVED:
{
synchronized (mLock) {
mSettingsRegistry.removeUserStateLocked(userId, true);
}
}
break;
case Intent.ACTION_USER_STOPPED:
{
synchronized (mLock) {
mSettingsRegistry.removeUserStateLocked(userId, false);
}
}
break;
}
}
}, userFilter);
PackageMonitor monitor = new PackageMonitor() {
@Override
public void onPackageRemoved(String packageName, int uid) {
synchronized (mLock) {
mSettingsRegistry.onPackageRemovedLocked(packageName, UserHandle.getUserId(uid));
}
}
};
// package changes
monitor.register(getContext(), BackgroundThread.getHandler().getLooper(), UserHandle.ALL, true);
}
use of android.content.BroadcastReceiver in project android_frameworks_base by AOSPA.
the class VibratorService method systemReady.
public void systemReady() {
mIm = mContext.getSystemService(InputManager.class);
mSettingObserver = new SettingsObserver(mH);
mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
mPowerManagerInternal.registerLowPowerModeObserver(new PowerManagerInternal.LowPowerModeListener() {
@Override
public void onLowPowerModeChanged(boolean enabled) {
updateInputDeviceVibrators();
}
});
mContext.getContentResolver().registerContentObserver(Settings.System.getUriFor(Settings.System.VIBRATE_INPUT_DEVICES), true, mSettingObserver, UserHandle.USER_ALL);
mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateInputDeviceVibrators();
}
}, new IntentFilter(Intent.ACTION_USER_SWITCHED), null, mH);
updateInputDeviceVibrators();
}
use of android.content.BroadcastReceiver in project android_frameworks_base by AOSPA.
the class BroadcastTest method testLocalReceivePermissionDenied.
public void testLocalReceivePermissionDenied() throws Exception {
setExpectedReceivers(new String[] { RECEIVER_RESULTS });
BroadcastReceiver finish = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
gotReceive(RECEIVER_RESULTS, intent);
}
};
getContext().sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_LOCAL_DENIED), null, finish, null, Activity.RESULT_CANCELED, null, null);
waitForResultOrThrow(BROADCAST_TIMEOUT);
}
Aggregations