Search in sources :

Example 61 with BroadcastReceiver

use of android.content.BroadcastReceiver in project weex-example by KalicyZhou.

the class IndexActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_index);
    setContainer((ViewGroup) findViewById(R.id.index_container));
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    mProgressBar = (ProgressBar) findViewById(R.id.index_progressBar);
    mTipView = (TextView) findViewById(R.id.index_tip);
    mProgressBar.setVisibility(View.VISIBLE);
    mTipView.setVisibility(View.VISIBLE);
    if (!WXSoInstallMgrSdk.isCPUSupport()) {
        mProgressBar.setVisibility(View.INVISIBLE);
        mTipView.setText(R.string.cpu_not_support_tip);
        return;
    }
    if (TextUtils.equals(sCurrentIp, DEFAULT_IP)) {
        renderPage(WXFileUtils.loadAsset("index.js", this), getIndexUrl());
    } else {
        renderPageByURL(getIndexUrl());
    }
    mReloadReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            createWeexInstance();
            if (TextUtils.equals(sCurrentIp, DEFAULT_IP)) {
                renderPage(WXFileUtils.loadAsset("index.js", getApplicationContext()), getIndexUrl());
            } else {
                renderPageByURL(getIndexUrl());
            }
            mProgressBar.setVisibility(View.VISIBLE);
        }
    };
    LocalBroadcastManager.getInstance(this).registerReceiver(mReloadReceiver, new IntentFilter(WXSDKEngine.JS_FRAMEWORK_RELOAD));
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) Toolbar(android.support.v7.widget.Toolbar)

Example 62 with BroadcastReceiver

use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.

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_PULSE_ON_DOUBLE_TAP), 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 63 with BroadcastReceiver

use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.

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 64 with BroadcastReceiver

use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.

the class TelecomLoaderService method registerCarrierConfigChangedReceiver.

private void registerCarrierConfigChangedReceiver() {
    final PackageManagerInternal packageManagerInternal = LocalServices.getService(PackageManagerInternal.class);
    BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED)) {
                for (int userId : UserManagerService.getInstance().getUserIds()) {
                    updateSimCallManagerPermissions(packageManagerInternal, userId);
                }
            }
        }
    };
    mContext.registerReceiverAsUser(receiver, UserHandle.ALL, new IntentFilter(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED), null, null);
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) PackageManagerInternal(android.content.pm.PackageManagerInternal) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 65 with BroadcastReceiver

use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.

the class ShutdownThread method run.

/**
     * Makes sure we handle the shutdown gracefully.
     * Shuts off power regardless of radio and bluetooth state if the alloted time has passed.
     */
public void run() {
    BroadcastReceiver br = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            // We don't allow apps to cancel this, so ignore the result.
            actionDone();
        }
    };
    /*
         * Write a system property in case the system_server reboots before we
         * get to the actual hardware restart. If that happens, we'll retry at
         * the beginning of the SystemServer startup.
         */
    {
        String reason = (mReboot ? "1" : "0") + (mReason != null ? mReason : "");
        SystemProperties.set(SHUTDOWN_ACTION_PROPERTY, reason);
    }
    /*
         * If we are rebooting into safe mode, write a system property
         * indicating so.
         */
    if (mRebootSafeMode) {
        SystemProperties.set(REBOOT_SAFEMODE_PROPERTY, "1");
    }
    Log.i(TAG, "Sending shutdown broadcast...");
    // First send the high-level shut down broadcast.
    mActionDone = false;
    Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
    intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, null, br, mHandler, 0, null, null);
    final long endTime = SystemClock.elapsedRealtime() + MAX_BROADCAST_TIME;
    synchronized (mActionDoneSync) {
        while (!mActionDone) {
            long delay = endTime - SystemClock.elapsedRealtime();
            if (delay <= 0) {
                Log.w(TAG, "Shutdown broadcast timed out");
                break;
            } else if (mRebootHasProgressBar) {
                int status = (int) ((MAX_BROADCAST_TIME - delay) * 1.0 * BROADCAST_STOP_PERCENT / MAX_BROADCAST_TIME);
                sInstance.setRebootProgress(status, null);
            }
            try {
                mActionDoneSync.wait(Math.min(delay, PHONE_STATE_POLL_SLEEP_MSEC));
            } catch (InterruptedException e) {
            }
        }
    }
    if (mRebootHasProgressBar) {
        sInstance.setRebootProgress(BROADCAST_STOP_PERCENT, null);
    }
    Log.i(TAG, "Shutting down activity manager...");
    final IActivityManager am = ActivityManagerNative.asInterface(ServiceManager.checkService("activity"));
    if (am != null) {
        try {
            am.shutdown(MAX_BROADCAST_TIME);
        } catch (RemoteException e) {
        }
    }
    if (mRebootHasProgressBar) {
        sInstance.setRebootProgress(ACTIVITY_MANAGER_STOP_PERCENT, null);
    }
    Log.i(TAG, "Shutting down package manager...");
    final PackageManagerService pm = (PackageManagerService) ServiceManager.getService("package");
    if (pm != null) {
        pm.shutdown();
    }
    if (mRebootHasProgressBar) {
        sInstance.setRebootProgress(PACKAGE_MANAGER_STOP_PERCENT, null);
    }
    // Shutdown radios.
    shutdownRadios(MAX_RADIO_WAIT_TIME);
    if (mRebootHasProgressBar) {
        sInstance.setRebootProgress(RADIO_STOP_PERCENT, null);
    }
    // Shutdown MountService to ensure media is in a safe state
    IMountShutdownObserver observer = new IMountShutdownObserver.Stub() {

        public void onShutDownComplete(int statusCode) throws RemoteException {
            Log.w(TAG, "Result code " + statusCode + " from MountService.shutdown");
            actionDone();
        }
    };
    Log.i(TAG, "Shutting down MountService");
    // Set initial variables and time out time.
    mActionDone = false;
    final long endShutTime = SystemClock.elapsedRealtime() + MAX_SHUTDOWN_WAIT_TIME;
    synchronized (mActionDoneSync) {
        try {
            final IMountService mount = IMountService.Stub.asInterface(ServiceManager.checkService("mount"));
            if (mount != null) {
                mount.shutdown(observer);
            } else {
                Log.w(TAG, "MountService unavailable for shutdown");
            }
        } catch (Exception e) {
            Log.e(TAG, "Exception during MountService shutdown", e);
        }
        while (!mActionDone) {
            long delay = endShutTime - SystemClock.elapsedRealtime();
            if (delay <= 0) {
                Log.w(TAG, "Shutdown wait timed out");
                break;
            } else if (mRebootHasProgressBar) {
                int status = (int) ((MAX_SHUTDOWN_WAIT_TIME - delay) * 1.0 * (MOUNT_SERVICE_STOP_PERCENT - RADIO_STOP_PERCENT) / MAX_SHUTDOWN_WAIT_TIME);
                status += RADIO_STOP_PERCENT;
                sInstance.setRebootProgress(status, null);
            }
            try {
                mActionDoneSync.wait(Math.min(delay, PHONE_STATE_POLL_SLEEP_MSEC));
            } catch (InterruptedException e) {
            }
        }
    }
    if (mRebootHasProgressBar) {
        sInstance.setRebootProgress(MOUNT_SERVICE_STOP_PERCENT, null);
        // If it's to reboot to install an update and uncrypt hasn't been
        // done yet, trigger it now.
        uncrypt();
    }
    rebootOrShutdown(mContext, mReboot, mReason);
}
Also used : Context(android.content.Context) IMountShutdownObserver(android.os.storage.IMountShutdownObserver) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) RemoteException(android.os.RemoteException) ErrnoException(android.system.ErrnoException) IOException(java.io.IOException) PackageManagerService(com.android.server.pm.PackageManagerService) IMountService(android.os.storage.IMountService) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Aggregations

BroadcastReceiver (android.content.BroadcastReceiver)637 Intent (android.content.Intent)564 Context (android.content.Context)493 IntentFilter (android.content.IntentFilter)441 PendingIntent (android.app.PendingIntent)120 Test (org.junit.Test)109 ArrayList (java.util.ArrayList)34 RemoteException (android.os.RemoteException)29 Bundle (android.os.Bundle)24 IOException (java.io.IOException)23 Point (android.graphics.Point)20 Semaphore (java.util.concurrent.Semaphore)20 View (android.view.View)19 Handler (android.os.Handler)18 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)17 ComponentName (android.content.ComponentName)16 TextView (android.widget.TextView)16 PackageMonitor (com.android.internal.content.PackageMonitor)15 ApplicationInfo (android.content.pm.ApplicationInfo)14 AndroidRuntimeException (android.util.AndroidRuntimeException)14