Search in sources :

Example 86 with PendingIntent

use of android.app.PendingIntent in project platform_frameworks_base by android.

the class DeviceStorageMonitorService method sendNotification.

/**
    * This method sends a notification to NotificationManager to display
    * an error dialog indicating low disk space and launch the Installer
    * application
    */
private void sendNotification() {
    final Context context = getContext();
    if (localLOGV)
        Slog.i(TAG, "Sending low memory notification");
    //log the event to event log with the amount of free storage(in bytes) left on the device
    EventLog.writeEvent(EventLogTags.LOW_STORAGE, mFreeMem);
    //  Pack up the values and broadcast them to everyone
    Intent lowMemIntent = new Intent(StorageManager.ACTION_MANAGE_STORAGE);
    lowMemIntent.putExtra("memory", mFreeMem);
    lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    NotificationManager mNotificationMgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence title = context.getText(com.android.internal.R.string.low_internal_storage_view_title);
    CharSequence details = context.getText(mIsBootImageOnDisk ? com.android.internal.R.string.low_internal_storage_view_text : com.android.internal.R.string.low_internal_storage_view_text_no_boot);
    PendingIntent intent = PendingIntent.getActivityAsUser(context, 0, lowMemIntent, 0, null, UserHandle.CURRENT);
    Notification notification = new Notification.Builder(context).setSmallIcon(com.android.internal.R.drawable.stat_notify_disk_full).setTicker(title).setColor(context.getColor(com.android.internal.R.color.system_notification_accent_color)).setContentTitle(title).setContentText(details).setContentIntent(intent).setStyle(new Notification.BigTextStyle().bigText(details)).setVisibility(Notification.VISIBILITY_PUBLIC).setCategory(Notification.CATEGORY_SYSTEM).build();
    notification.flags |= Notification.FLAG_NO_CLEAR;
    mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification, UserHandle.ALL);
    context.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL);
}
Also used : Context(android.content.Context) NotificationManager(android.app.NotificationManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 87 with PendingIntent

use of android.app.PendingIntent in project platform_frameworks_base by android.

the class DevicePolicyManagerService method setExpirationAlarmCheckLocked.

/**
     * Set an alarm for an upcoming event - expiration warning, expiration, or post-expiration
     * reminders.  Clears alarm if no expirations are configured.
     */
private void setExpirationAlarmCheckLocked(Context context, int userHandle, boolean parent) {
    final long expiration = getPasswordExpirationLocked(null, userHandle, parent);
    final long now = System.currentTimeMillis();
    final long timeToExpire = expiration - now;
    final long alarmTime;
    if (expiration == 0) {
        // No expirations are currently configured:  Cancel alarm.
        alarmTime = 0;
    } else if (timeToExpire <= 0) {
        // The password has already expired:  Repeat every 24 hours.
        alarmTime = now + MS_PER_DAY;
    } else {
        // Selecting the next alarm time:  Roll forward to the next 24 hour multiple before
        // the expiration time.
        long alarmInterval = timeToExpire % MS_PER_DAY;
        if (alarmInterval == 0) {
            alarmInterval = MS_PER_DAY;
        }
        alarmTime = now + alarmInterval;
    }
    long token = mInjector.binderClearCallingIdentity();
    try {
        int affectedUserHandle = parent ? getProfileParentId(userHandle) : userHandle;
        AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        PendingIntent pi = PendingIntent.getBroadcastAsUser(context, REQUEST_EXPIRE_PASSWORD, new Intent(ACTION_EXPIRED_PASSWORD_NOTIFICATION), PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT, UserHandle.of(affectedUserHandle));
        am.cancel(pi);
        if (alarmTime != 0) {
            am.set(AlarmManager.RTC, alarmTime, pi);
        }
    } finally {
        mInjector.binderRestoreCallingIdentity(token);
    }
}
Also used : AlarmManager(android.app.AlarmManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 88 with PendingIntent

use of android.app.PendingIntent in project platform_frameworks_base by android.

the class SinkActivity method connect.

private void connect(UsbDevice device) {
    if (mConnected) {
        disconnect();
    }
    // Check whether we have permission to access the device.
    if (!mUsbManager.hasPermission(device)) {
        mLogger.log("Prompting the user for access to the device.");
        Intent intent = new Intent(ACTION_USB_DEVICE_PERMISSION);
        intent.setPackage(getPackageName());
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        mUsbManager.requestPermission(device, pendingIntent);
        return;
    }
    // Claim the device.
    UsbDeviceConnection conn = mUsbManager.openDevice(device);
    if (conn == null) {
        mLogger.logError("Could not obtain device connection.");
        return;
    }
    UsbInterface iface = device.getInterface(0);
    UsbEndpoint controlEndpoint = iface.getEndpoint(0);
    if (!conn.claimInterface(iface, true)) {
        mLogger.logError("Could not claim interface.");
        return;
    }
    try {
        // If already in accessory mode, then connect to the device.
        if (isAccessory(device)) {
            mLogger.log("Connecting to accessory...");
            int protocolVersion = getProtocol(conn);
            if (protocolVersion < 1) {
                mLogger.logError("Device does not support accessory protocol.");
                return;
            }
            mLogger.log("Protocol version: " + protocolVersion);
            // Setup bulk endpoints.
            UsbEndpoint bulkIn = null;
            UsbEndpoint bulkOut = null;
            for (int i = 0; i < iface.getEndpointCount(); i++) {
                UsbEndpoint ep = iface.getEndpoint(i);
                if (ep.getDirection() == UsbConstants.USB_DIR_IN) {
                    if (bulkIn == null) {
                        mLogger.log(String.format("Bulk IN endpoint: %d", i));
                        bulkIn = ep;
                    }
                } else {
                    if (bulkOut == null) {
                        mLogger.log(String.format("Bulk OUT endpoint: %d", i));
                        bulkOut = ep;
                    }
                }
            }
            if (bulkIn == null || bulkOut == null) {
                mLogger.logError("Unable to find bulk endpoints");
                return;
            }
            mLogger.log("Connected");
            mConnected = true;
            mDevice = device;
            mProtocolVersion = protocolVersion;
            mAccessoryInterface = iface;
            mAccessoryConnection = conn;
            mControlEndpoint = controlEndpoint;
            mTransport = new UsbAccessoryBulkTransport(mLogger, conn, bulkIn, bulkOut);
            if (mProtocolVersion >= 2) {
                registerHid();
            }
            startServices();
            mTransport.startReading();
            return;
        }
        // Do accessory negotiation.
        mLogger.log("Attempting to switch device to accessory mode...");
        // Send get protocol.
        int protocolVersion = getProtocol(conn);
        if (protocolVersion < 1) {
            mLogger.logError("Device does not support accessory protocol.");
            return;
        }
        mLogger.log("Protocol version: " + protocolVersion);
        // Send identifying strings.
        sendString(conn, UsbAccessoryConstants.ACCESSORY_STRING_MANUFACTURER, MANUFACTURER);
        sendString(conn, UsbAccessoryConstants.ACCESSORY_STRING_MODEL, MODEL);
        sendString(conn, UsbAccessoryConstants.ACCESSORY_STRING_DESCRIPTION, DESCRIPTION);
        sendString(conn, UsbAccessoryConstants.ACCESSORY_STRING_VERSION, VERSION);
        sendString(conn, UsbAccessoryConstants.ACCESSORY_STRING_URI, URI);
        sendString(conn, UsbAccessoryConstants.ACCESSORY_STRING_SERIAL, SERIAL);
        // Send start.
        // The device should re-enumerate as an accessory.
        mLogger.log("Sending accessory start request.");
        int len = conn.controlTransfer(UsbConstants.USB_DIR_OUT | UsbConstants.USB_TYPE_VENDOR, UsbAccessoryConstants.ACCESSORY_START, 0, 0, null, 0, 10000);
        if (len != 0) {
            mLogger.logError("Device refused to switch to accessory mode.");
        } else {
            mLogger.log("Waiting for device to re-enumerate...");
        }
    } finally {
        if (!mConnected) {
            conn.releaseInterface(iface);
        }
    }
}
Also used : UsbDeviceConnection(android.hardware.usb.UsbDeviceConnection) UsbInterface(android.hardware.usb.UsbInterface) UsbEndpoint(android.hardware.usb.UsbEndpoint) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) UsbEndpoint(android.hardware.usb.UsbEndpoint)

Example 89 with PendingIntent

use of android.app.PendingIntent in project platform_frameworks_base by android.

the class ManagedApplicationService method connect.

/**
     * Asynchronously bind to the application service if not bound.
     */
public void connect() {
    synchronized (mLock) {
        if (mConnection != null || mPendingConnection != null) {
            // We're already connected or are trying to connect
            return;
        }
        final PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mSettingsAction), 0);
        final Intent intent = new Intent().setComponent(mComponent).putExtra(Intent.EXTRA_CLIENT_LABEL, mClientLabel).putExtra(Intent.EXTRA_CLIENT_INTENT, pendingIntent);
        final ServiceConnection serviceConnection = new ServiceConnection() {

            @Override
            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
                IInterface iface = null;
                PendingEvent pendingEvent = null;
                synchronized (mLock) {
                    if (mPendingConnection == this) {
                        // No longer pending, remove from pending connection
                        mPendingConnection = null;
                        mConnection = this;
                    } else {
                        // Service connection wasn't pending, must have been disconnected
                        mContext.unbindService(this);
                        return;
                    }
                    try {
                        iBinder.linkToDeath(mDeathRecipient, 0);
                        mBoundInterface = mChecker.asInterface(iBinder);
                        if (!mChecker.checkType(mBoundInterface)) {
                            // Received an invalid binder, disconnect
                            mContext.unbindService(this);
                            mBoundInterface = null;
                        }
                        iface = mBoundInterface;
                        pendingEvent = mPendingEvent;
                        mPendingEvent = null;
                    } catch (RemoteException e) {
                        // DOA
                        Slog.w(TAG, "Unable to bind service: " + intent, e);
                        mBoundInterface = null;
                    }
                }
                if (iface != null && pendingEvent != null) {
                    try {
                        pendingEvent.runEvent(iface);
                    } catch (RuntimeException | RemoteException ex) {
                        Slog.e(TAG, "Received exception from user service: ", ex);
                    }
                }
            }

            @Override
            public void onServiceDisconnected(ComponentName componentName) {
                Slog.w(TAG, "Service disconnected: " + intent);
                mConnection = null;
                mBoundInterface = null;
            }
        };
        mPendingConnection = serviceConnection;
        try {
            if (!mContext.bindServiceAsUser(intent, serviceConnection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(mUserId))) {
                Slog.w(TAG, "Unable to bind service: " + intent);
            }
        } catch (SecurityException e) {
            Slog.w(TAG, "Unable to bind service: " + intent, e);
        }
    }
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) UserHandle(android.os.UserHandle) IInterface(android.os.IInterface) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException)

Example 90 with PendingIntent

use of android.app.PendingIntent in project smooth-app-bar-layout by henrytao-me.

the class BaseActivity method onDonate.

private void onDonate(PurchaseItem item) {
    if (item == null || !item.isValid() || mBillingService == null) {
        return;
    }
    try {
        Bundle buyIntentBundle = mBillingService.getBuyIntent(3, getPackageName(), item.getId(), "inapp", "");
        PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
        startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), 0, 0, 0);
    } catch (RemoteException e) {
        e.printStackTrace();
    } catch (IntentSender.SendIntentException e) {
        e.printStackTrace();
    }
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) RemoteException(android.os.RemoteException) IntentSender(android.content.IntentSender)

Aggregations

PendingIntent (android.app.PendingIntent)1243 Intent (android.content.Intent)1043 Notification (android.app.Notification)233 NotificationCompat (android.support.v4.app.NotificationCompat)184 NotificationManager (android.app.NotificationManager)160 AlarmManager (android.app.AlarmManager)153 Bundle (android.os.Bundle)78 RemoteViews (android.widget.RemoteViews)67 RemoteException (android.os.RemoteException)64 Resources (android.content.res.Resources)63 Bitmap (android.graphics.Bitmap)62 Context (android.content.Context)59 ComponentName (android.content.ComponentName)56 Uri (android.net.Uri)45 Test (org.junit.Test)44 IntentFilter (android.content.IntentFilter)43 SharedPreferences (android.content.SharedPreferences)38 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)34 UserHandle (android.os.UserHandle)31 IOException (java.io.IOException)30