android.support.v4.app.BundleCompat Java Examples

The following examples show how to use android.support.v4.app.BundleCompat. 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: MediaBrowserCompat.java    From letv with Apache License 2.0 6 votes vote down vote up
public void onConnected() {
    Bundle extras = MediaBrowserCompatApi21.getExtras(this.mBrowserObj);
    if (extras != null) {
        IBinder serviceBinder = BundleCompat.getBinder(extras, MediaBrowserProtocol.EXTRA_MESSENGER_BINDER);
        if (serviceBinder != null) {
            this.mServiceBinderWrapper = new ServiceBinderWrapper(serviceBinder);
            this.mCallbacksMessenger = new Messenger(this.mHandler);
            this.mHandler.setCallbacksMessenger(this.mCallbacksMessenger);
            try {
                this.mServiceBinderWrapper.registerCallbackMessenger(this.mCallbacksMessenger);
            } catch (RemoteException e) {
                Log.i(MediaBrowserCompat.TAG, "Remote error registering client messenger.");
            }
            onServiceConnected(this.mCallbacksMessenger, null, null, null);
        }
    }
}
 
Example #2
Source File: TrustedWebUtils.java    From custom-tabs-client with Apache License 2.0 6 votes vote down vote up
/**
 * Open the site settings for given url in the web browser. The url must belong to the origin
 * associated with the calling application via the Digital Asset Links. Prior to calling, one
 * must establish a connection to {@link CustomTabsService} and create a
 * {@link CustomTabsSession}.
 *
 * It is also required to do {@link CustomTabsClient#warmup} and
 * {@link CustomTabsSession#validateRelationship} before calling this method.
 *
 * @param context {@link Context} to use while launching site-settings activity.
 * @param session The {@link CustomTabsSession} used to verify the origin.
 * @param uri The {@link Uri} for which site-settings are to be shown.
 */
public static void launchBrowserSiteSettings(Context context, CustomTabsSession session,
        Uri uri) {
    Intent intent = new Intent(TrustedWebUtils.ACTION_MANAGE_TRUSTED_WEB_ACTIVITY_DATA);
    intent.setPackage(session.getComponentName().getPackageName());
    intent.setData(uri);

    Bundle bundle = new Bundle();
    BundleCompat.putBinder(bundle, CustomTabsIntent.EXTRA_SESSION, session.getBinder());
    intent.putExtras(bundle);
    PendingIntent id = session.getId();
    if (id != null) {
        intent.putExtra(CustomTabsIntent.EXTRA_SESSION_ID, id);
    }
    context.startActivity(intent);
}
 
Example #3
Source File: IntentUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts a {@link Binder} value into an Intent as an extra.
 *
 * Uses {@link BundleCompat#putBinder()}, but doesn't throw exceptions.
 *
 * @param intent Intent to put the binder into.
 * @param name Key.
 * @param binder Binder object.
 */
@VisibleForTesting
public static void safePutBinderExtra(Intent intent, String name, IBinder binder) {
    if (intent == null) return;
    Bundle bundle = new Bundle();
    try {
        BundleCompat.putBinder(bundle, name, binder);
    } catch (Throwable t) {
        // Catches parceling exceptions.
        Log.e(TAG, "putBinder failed on bundle " + bundle);
    }
    intent.putExtras(bundle);
}
 
Example #4
Source File: IntentUtils.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Just like {@link BundleCompat#getBinder()}, but doesn't throw exceptions.
 */
public static IBinder safeGetBinder(Bundle bundle, String name) {
    if (bundle == null) return null;
    try {
        return BundleCompat.getBinder(bundle, name);
    } catch (Throwable t) {
        // Catches un-parceling exceptions.
        Log.e(TAG, "getBinder failed on bundle " + bundle);
        return null;
    }
}
 
Example #5
Source File: IntentUtils.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Just like {@link BundleCompat#getBinder()}, but doesn't throw exceptions.
 */
public static IBinder safeGetBinder(Bundle bundle, String name) {
    if (bundle == null) return null;
    try {
        return BundleCompat.getBinder(bundle, name);
    } catch (Throwable t) {
        // Catches un-parceling exceptions.
        Log.e(TAG, "getBinder failed on bundle " + bundle);
        return null;
    }
}
 
Example #6
Source File: IntentUtils.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts a {@link Binder} value into an Intent as an extra.
 *
 * Uses {@link BundleCompat#putBinder()}, but doesn't throw exceptions.
 *
 * @param intent Intent to put the binder into.
 * @param name Key.
 * @param binder Binder object.
 */
@VisibleForTesting
public static void safePutBinderExtra(Intent intent, String name, IBinder binder) {
    if (intent == null) return;
    Bundle bundle = new Bundle();
    try {
        BundleCompat.putBinder(bundle, name, binder);
    } catch (Throwable t) {
        // Catches parceling exceptions.
        Log.e(TAG, "putBinder failed on bundle " + bundle);
    }
    intent.putExtras(bundle);
}
 
Example #7
Source File: IntentUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Just like {@link BundleCompat#getBinder()}, but doesn't throw exceptions.
 */
public static IBinder safeGetBinder(Bundle bundle, String name) {
    if (bundle == null) return null;
    try {
        return BundleCompat.getBinder(bundle, name);
    } catch (Throwable t) {
        // Catches un-parceling exceptions.
        Log.e(TAG, "getBinder failed on bundle " + bundle);
        return null;
    }
}
 
Example #8
Source File: IntentUtils.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Inserts a {@link Binder} value into an Intent as an extra.
 *
 * Uses {@link BundleCompat#putBinder()}, but doesn't throw exceptions.
 *
 * @param intent Intent to put the binder into.
 * @param name Key.
 * @param binder Binder object.
 */
@VisibleForTesting
public static void safePutBinderExtra(Intent intent, String name, IBinder binder) {
    if (intent == null) return;
    Bundle bundle = new Bundle();
    try {
        BundleCompat.putBinder(bundle, name, binder);
    } catch (Throwable t) {
        // Catches parceling exceptions.
        Log.e(TAG, "putBinder failed on bundle " + bundle);
    }
    intent.putExtras(bundle);
}
 
Example #9
Source File: CustomTabsIntent.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
private void setSessionParameters(@Nullable IBinder session,
        @Nullable PendingIntent sessionId) {
    Bundle bundle = new Bundle();
    BundleCompat.putBinder(bundle, EXTRA_SESSION, session);
    if (sessionId != null) {
        bundle.putParcelable(EXTRA_SESSION_ID, sessionId);
    }

    mIntent.putExtras(bundle);
}
 
Example #10
Source File: CustomTabsSessionToken.java    From custom-tabs-client with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain a {@link CustomTabsSessionToken} from an intent. See {@link CustomTabsIntent.Builder}
 * for ways to generate an intent for custom tabs.
 * @param intent The intent to generate the token from. This has to include an extra for
 *               {@link CustomTabsIntent#EXTRA_SESSION}.
 * @return The token that was generated.
 */
@Nullable
public static CustomTabsSessionToken getSessionTokenFromIntent(Intent intent) {
    Bundle b = intent.getExtras();
    if (b == null) return null;
    IBinder binder = BundleCompat.getBinder(b, CustomTabsIntent.EXTRA_SESSION);
    PendingIntent sessionId = intent.getParcelableExtra(CustomTabsIntent.EXTRA_SESSION_ID);
    if (binder == null && sessionId == null) return null;
    return new CustomTabsSessionToken(ICustomTabsCallback.Stub.asInterface(binder), sessionId);
}
 
Example #11
Source File: IBinderCoderTest.java    From lyra with Apache License 2.0 4 votes vote down vote up
@Test
public void testSerializeIBinder() {
    IBinder expectedValue = new Binder();
    mCoder.serialize(bundle(), randomKey(), expectedValue);
    assertEquals(expectedValue, BundleCompat.getBinder(bundle(), randomKey()));
}
 
Example #12
Source File: IBinderCoderTest.java    From lyra with Apache License 2.0 4 votes vote down vote up
@Test
public void testDeserializeIBinder() {
    IBinder expectedValue = new Binder();
    BundleCompat.putBinder(bundle(), randomKey(), expectedValue);
    assertEquals(expectedValue, mCoder.deserialize(bundle(), randomKey()));
}
 
Example #13
Source File: CustomTabsIntent.java    From 365browser with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a {@link CustomTabsIntent.Builder} object associated with a given
 * {@link CustomTabsSession}.
 *
 * Guarantees that the {@link Intent} will be sent to the same component as the one the
 * session is associated with.
 *
 * @param session The session to associate this Builder with.
 */
public Builder(@Nullable CustomTabsSession session) {
    if (session != null) mIntent.setPackage(session.getComponentName().getPackageName());
    Bundle bundle = new Bundle();
    BundleCompat.putBinder(
            bundle, EXTRA_SESSION, session == null ? null : session.getBinder());
    mIntent.putExtras(bundle);
}
 
Example #14
Source File: CustomTabsSessionToken.java    From TelePlus-Android with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtain a {@link CustomTabsSessionToken} from an intent. See {@link CustomTabsIntent.Builder}
 * for ways to generate an intent for custom tabs.
 * @param intent The intent to generate the token from. This has to include an extra for
 *               {@link CustomTabsIntent#EXTRA_SESSION}.
 * @return The token that was generated.
 */
public static CustomTabsSessionToken getSessionTokenFromIntent(Intent intent) {
    Bundle b = intent.getExtras();
    IBinder binder = BundleCompat.getBinder(b, CustomTabsIntent.EXTRA_SESSION);
    if (binder == null) return null;
    return new CustomTabsSessionToken(ICustomTabsCallback.Stub.asInterface(binder));
}
 
Example #15
Source File: CustomTabsSessionToken.java    From 365browser with Apache License 2.0 3 votes vote down vote up
/**
 * Obtain a {@link CustomTabsSessionToken} from an intent. See {@link CustomTabsIntent.Builder}
 * for ways to generate an intent for custom tabs.
 * @param intent The intent to generate the token from. This has to include an extra for
 *               {@link CustomTabsIntent#EXTRA_SESSION}.
 * @return The token that was generated.
 */
public static CustomTabsSessionToken getSessionTokenFromIntent(Intent intent) {
    Bundle b = intent.getExtras();
    IBinder binder = BundleCompat.getBinder(b, CustomTabsIntent.EXTRA_SESSION);
    if (binder == null) return null;
    return new CustomTabsSessionToken(ICustomTabsCallback.Stub.asInterface(binder));
}
 
Example #16
Source File: CustomTabsIntent.java    From AndroidChromium with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a {@link CustomTabsIntent.Builder} object associated with a given
 * {@link CustomTabsSession}.
 *
 * Guarantees that the {@link Intent} will be sent to the same component as the one the
 * session is associated with.
 *
 * @param session The session to associate this Builder with.
 */
public Builder(@Nullable CustomTabsSession session) {
    if (session != null) mIntent.setPackage(session.getComponentName().getPackageName());
    Bundle bundle = new Bundle();
    BundleCompat.putBinder(
            bundle, EXTRA_SESSION, session == null ? null : session.getBinder());
    mIntent.putExtras(bundle);
}
 
Example #17
Source File: CustomTabsSessionToken.java    From AndroidChromium with Apache License 2.0 3 votes vote down vote up
/**
 * Obtain a {@link CustomTabsSessionToken} from an intent. See {@link CustomTabsIntent.Builder}
 * for ways to generate an intent for custom tabs.
 * @param intent The intent to generate the token from. This has to include an extra for
 *               {@link CustomTabsIntent#EXTRA_SESSION}.
 * @return The token that was generated.
 */
public static CustomTabsSessionToken getSessionTokenFromIntent(Intent intent) {
    Bundle b = intent.getExtras();
    IBinder binder = BundleCompat.getBinder(b, CustomTabsIntent.EXTRA_SESSION);
    if (binder == null) return null;
    return new CustomTabsSessionToken(ICustomTabsCallback.Stub.asInterface(binder));
}
 
Example #18
Source File: CustomTabsIntent.java    From TelePlus-Android with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a {@link CustomTabsIntent.Builder} object associated with a given
 * {@link CustomTabsSession}.
 *
 * Guarantees that the {@link Intent} will be sent to the same component as the one the
 * session is associated with.
 *
 * @param session The session to associate this Builder with.
 */
public Builder(@Nullable CustomTabsSession session) {
    if (session != null) mIntent.setPackage(session.getComponentName().getPackageName());
    Bundle bundle = new Bundle();
    BundleCompat.putBinder(
            bundle, EXTRA_SESSION, session == null ? null : session.getBinder());
    mIntent.putExtras(bundle);
}
 
Example #19
Source File: CustomTabsSessionToken.java    From TelePlus-Android with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtain a {@link CustomTabsSessionToken} from an intent. See {@link CustomTabsIntent.Builder}
 * for ways to generate an intent for custom tabs.
 * @param intent The intent to generate the token from. This has to include an extra for
 *               {@link CustomTabsIntent#EXTRA_SESSION}.
 * @return The token that was generated.
 */
public static CustomTabsSessionToken getSessionTokenFromIntent(Intent intent) {
    Bundle b = intent.getExtras();
    IBinder binder = BundleCompat.getBinder(b, CustomTabsIntent.EXTRA_SESSION);
    if (binder == null) return null;
    return new CustomTabsSessionToken(ICustomTabsCallback.Stub.asInterface(binder));
}
 
Example #20
Source File: CustomTabsIntent.java    From TelePlus-Android with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Creates a {@link CustomTabsIntent.Builder} object associated with a given
 * {@link CustomTabsSession}.
 *
 * Guarantees that the {@link Intent} will be sent to the same component as the one the
 * session is associated with.
 *
 * @param session The session to associate this Builder with.
 */
public Builder(@Nullable CustomTabsSession session) {
    if (session != null) mIntent.setPackage(session.getComponentName().getPackageName());
    Bundle bundle = new Bundle();
    BundleCompat.putBinder(
            bundle, EXTRA_SESSION, session == null ? null : session.getBinder());
    mIntent.putExtras(bundle);
}
 
Example #21
Source File: IBinderCoder.java    From lyra with Apache License 2.0 2 votes vote down vote up
/**
 * Write a field's value into the saved state {@link Bundle}.
 *
 * @param state      {@link Bundle} used to save the state
 * @param key        key retrieved from {@code fieldDeclaringClass#fieldName}
 * @param fieldValue value of field
 */
@Override
public void serialize(@NonNull Bundle state, @NonNull String key, @NonNull IBinder fieldValue) {
    BundleCompat.putBinder(state, key, fieldValue);
}