Java Code Examples for android.content.Intent#ACTION_SHUTDOWN

The following examples show how to use android.content.Intent#ACTION_SHUTDOWN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntropyMixer.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** Test only interface, not for public use */
public EntropyMixer(
        Context context,
        String entropyFile,
        String randomDevice,
        String hwRandomDevice) {
    if (randomDevice == null) { throw new NullPointerException("randomDevice"); }
    if (hwRandomDevice == null) { throw new NullPointerException("hwRandomDevice"); }
    if (entropyFile == null) { throw new NullPointerException("entropyFile"); }

    this.randomDevice = randomDevice;
    this.hwRandomDevice = hwRandomDevice;
    this.entropyFile = entropyFile;
    loadInitialEntropy();
    addDeviceSpecificEntropy();
    addHwRandomEntropy();
    writeEntropy();
    scheduleEntropyWriter();
    IntentFilter broadcastFilter = new IntentFilter(Intent.ACTION_SHUTDOWN);
    broadcastFilter.addAction(Intent.ACTION_POWER_CONNECTED);
    broadcastFilter.addAction(Intent.ACTION_REBOOT);
    context.registerReceiver(
            mBroadcastReceiver,
            broadcastFilter,
            null, // do not require broadcaster to hold any permissions
            mHandler // process received broadcasts on the I/O thread instead of the main thread
            );
}
 
Example 2
Source File: HdmiControlService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@ServiceThreadOnly
@Override
public void onReceive(Context context, Intent intent) {
    assertRunOnServiceThread();
    switch (intent.getAction()) {
        case Intent.ACTION_SCREEN_OFF:
            if (isPowerOnOrTransient()) {
                onStandby(STANDBY_SCREEN_OFF);
            }
            break;
        case Intent.ACTION_SCREEN_ON:
            if (isPowerStandbyOrTransient()) {
                onWakeUp();
            }
            break;
        case Intent.ACTION_CONFIGURATION_CHANGED:
            String language = getMenuLanguage();
            if (!mLanguage.equals(language)) {
                onLanguageChanged(language);
            }
            break;
        case Intent.ACTION_SHUTDOWN:
            if (isPowerOnOrTransient()) {
                onStandby(STANDBY_SHUTDOWN);
            }
            break;
    }
}
 
Example 3
Source File: UserController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
void finishUserStopping(final int userId, final UserState uss) {
    // On to the next.
    final Intent shutdownIntent = new Intent(Intent.ACTION_SHUTDOWN);
    // This is the result receiver for the final shutdown broadcast.
    final IIntentReceiver shutdownReceiver = new IIntentReceiver.Stub() {
        @Override
        public void performReceive(Intent intent, int resultCode, String data,
                Bundle extras, boolean ordered, boolean sticky, int sendingUser) {
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    finishUserStopped(uss);
                }
            });
        }
    };

    synchronized (mLock) {
        if (uss.state != UserState.STATE_STOPPING) {
            // Whoops, we are being started back up.  Abort, abort!
            return;
        }
        uss.setState(UserState.STATE_SHUTDOWN);
    }
    mInjector.getUserManagerInternal().setUserState(userId, uss.state);

    mInjector.batteryStatsServiceNoteEvent(
            BatteryStats.HistoryItem.EVENT_USER_RUNNING_FINISH,
            Integer.toString(userId), userId);
    mInjector.getSystemServiceManager().stopUser(userId);

    mInjector.broadcastIntent(shutdownIntent,
            null, shutdownReceiver, 0, null, null, null,
            AppOpsManager.OP_NONE,
            null, true, false, MY_PID, SYSTEM_UID, userId);
}
 
Example 4
Source File: IntentUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取关机的意图
 * @param isNewTask 是否开启新的任务栈
 * @return 关机的意图
 */
public static Intent getShutdownIntent(final boolean isNewTask) {
    try {
        Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
        return getIntent(intent, isNewTask);
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getShutdownIntent");
    }
    return null;
}
 
Example 5
Source File: HyperionScreenService.java    From hyperion-android-grabber with MIT License 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    switch (Objects.requireNonNull(intent.getAction())) {
        case Intent.ACTION_SCREEN_ON:
            if (DEBUG) Log.v(TAG, "ACTION_SCREEN_ON intent received");
            if (mHyperionEncoder != null && !isCapturing()) {
                if (DEBUG) Log.v(TAG, "Encoder not grabbing, attempting to restart");
                mHyperionEncoder.resumeRecording();
            }
            notifyActivity();
        break;
        case Intent.ACTION_SCREEN_OFF:
            if (DEBUG) Log.v(TAG, "ACTION_SCREEN_OFF intent received");
            if (mHyperionEncoder != null) {
                if (DEBUG) Log.v(TAG, "Clearing current light data");
                mHyperionEncoder.clearLights();
            }
        break;
        case Intent.ACTION_CONFIGURATION_CHANGED:
            if (DEBUG) Log.v(TAG, "ACTION_CONFIGURATION_CHANGED intent received");
            if (mHyperionEncoder != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                if (DEBUG) Log.v(TAG, "Configuration changed, checking orientation");
                mHyperionEncoder.setOrientation(getResources().getConfiguration().orientation);
            }
        break;
        case Intent.ACTION_SHUTDOWN:
        case Intent.ACTION_REBOOT:
            if (DEBUG) Log.v(TAG, "ACTION_SHUTDOWN|ACTION_REBOOT intent received");
            stopScreenRecord();
        break;
    }
}
 
Example 6
Source File: ShutDownListen.java    From SystemUITuner2 with MIT License 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
    BroadcastReceiver mReceiver = new ShutDownReceiver();
    registerReceiver(mReceiver, filter);
    return super.onStartCommand(intent, flags, startId);
}
 
Example 7
Source File: DeviceEventUpdatesProvider.java    From PrivacyStreams with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String event = null;
    String type = null;

    switch(intent.getAction()){
        case Intent.ACTION_SCREEN_OFF:
            event = DeviceEvent.EVENT_SCREEN_OFF;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_SCREEN_ON:
            event = DeviceEvent.EVENT_SCREEN_ON;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_USER_PRESENT:
            event = DeviceEvent.EVENT_SCREEN_USER_PRESENT;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_BOOT_COMPLETED:
            event = DeviceEvent.EVENT_BOOT_COMPLETED;
            type = DeviceEvent.TYPE_BOOT;
            break;

        case Intent.ACTION_SHUTDOWN:
            event = DeviceEvent.EVENT_BOOT_SHUTDOWN;
            type = DeviceEvent.TYPE_BOOT;
            break;

        case Intent.ACTION_BATTERY_LOW:
            event = DeviceEvent.EVENT_BATTERY_LOW;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_BATTERY_OKAY:
            event = DeviceEvent.EVENT_BATTERY_OKAY;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_POWER_CONNECTED:
            event = DeviceEvent.EVENT_BATTERY_AC_CONNECTED;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_POWER_DISCONNECTED:
            event = DeviceEvent.EVENT_BATTERY_AC_DISCONNECTED;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case AudioManager.RINGER_MODE_CHANGED_ACTION:
            AudioManager am = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
            switch (am.getRingerMode()) {
                case AudioManager.RINGER_MODE_SILENT:
                    event = DeviceEvent.EVENT_RINGER_SILENT;
                    type = DeviceEvent.TYPE_RINGER;
                    break;

                case AudioManager.RINGER_MODE_VIBRATE:
                    event = DeviceEvent.EVENT_RINGER_VIBRATE;
                    type = DeviceEvent.TYPE_RINGER;
                    break;

                case AudioManager.RINGER_MODE_NORMAL:
                    event = DeviceEvent.EVENT_RINGER_NORMAL;
                    type = DeviceEvent.TYPE_RINGER;
                    break;
            }
        default:
            break;
    }

    if (type != null)
        output(new DeviceEvent(type, event));
}
 
Example 8
Source File: MainActivity.java    From SystemUITuner2 with MIT License 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setThings = new SetThings(this);
        fragment = new Fragment();
        fragmentManager = getSupportFragmentManager();
        handler = new Handler();

        mIntent = getIntent();
        Log.e("hue", mIntent.toString());

        main = new Main();
        qs = new QS();
        statbar = new StatBar();
        demo = new Demo();
        about = new About();
        settings = new Settings();
        misc = new Misc();
        touchwiz = new TouchWiz();

        IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
        shutDownReceiver = new ShutDownReceiver();
        registerReceiver(shutDownReceiver, filter);

        setContentView(R.layout.activity_main);

        String base64EncodedPublicKey = getResources().getText(R.string.dev_id).toString();
        mHelper = new IabHelper(this, base64EncodedPublicKey);

        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                Log.d(TAG, "Setup finished.");

                if (result.isSuccess()) {
                    // Oh noes, there was a problem.
                    complain("Problem setting up in-app billing: " + result);
                    return;
                }

                // Have we been disposed of in the meantime? If so, quit.
                if (mHelper == null) return;

                // Important: Dynamically register for broadcast messages about updated purchases.
                // We register the receiver here instead of as a <receiver> in the Manifest
                // because we always call getPurchases() at startup, so therefore we can ignore
                // any broadcasts sent while the app isn't running.
                // Note: registering this listener in an Activity is a bad idea, but is done here
                // because this is a SAMPLE. Regardless, the receiver must be registered after
                // IabHelper is setup, but before first call to getPurchases().
                mBroadcastReceiver = new IabBroadcastReceiver(MainActivity.this);
                IntentFilter broadcastFilter = new IntentFilter(IabBroadcastReceiver.ACTION);
                registerReceiver(mBroadcastReceiver, broadcastFilter);
            }
        });

        /*Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.setPopupTheme(setThings.style);

        Toolbar toolbar = new Toolbar(this);*/
        title = setThings.sharedPreferences.getString("currentTitle", getResources().getText(R.string.app_name).toString());

        setTitle(title); //set default title just because

        DrawerLayout drawer = findViewById(R.id.drawer_layout);
        toggle = new ActionBarDrawerToggle(
                this, drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        //noinspection deprecation
//        drawer.setDrawerListener(toggle);

        drawer.addDrawerListener(toggle);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setHomeButtonEnabled(true);
        }
        //noinspection deprecation
        getSupportActionBar().setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.colorPrimary2)));
        toggle.syncState();

        //for "organization"
        setup();
    }
 
Example 9
Source File: IntentUtils.java    From XKnife-Android with Apache License 2.0 2 votes vote down vote up
/**
 * 获取关机的意图
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.SHUTDOWN"/>}</p>
 *
 * @return intent shutdown intent
 */
public static Intent getShutdownIntent() {
    Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
 
Example 10
Source File: IntentUtils.java    From Android-UtilCode with Apache License 2.0 2 votes vote down vote up
/**
 * 获取关机的意图
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.SHUTDOWN"/>}</p>
 *
 * @return intent
 */
public static Intent getShutdownIntent() {
    Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}