use of androidx.browser.customtabs.CustomTabsCallback in project android-browser-helper by GoogleChrome.
the class TwaQualityEnforcerTest method triggerQualityEnforcement_NoCrashReason.
@Test
public void triggerQualityEnforcement_NoCrashReason() {
Runnable launchRunnable = () -> mTwaLauncher.launch(new TrustedWebActivityIntentBuilder(URL), mCustomTabsCallback, null, null);
CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFromIntent(getBrowserActivityWhenLaunched(launchRunnable).getIntent());
CustomTabsCallback callback = token.getCallback();
Bundle args = Bundle.EMPTY;
Bundle result = callback.extraCallbackWithResult(QualityEnforcer.CRASH, args);
assertFalse(result.getBoolean(QualityEnforcer.KEY_SUCCESS));
}
use of androidx.browser.customtabs.CustomTabsCallback in project MaxLock by Maxr1998.
the class SettingsActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
Util.setTheme(this);
super.onCreate(savedInstanceState);
if (MLPreferences.getPreferences(this).getInt(FirstStartActivity.FIRST_START_LAST_VERSION_KEY, 0) != FirstStartActivity.FIRST_START_LATEST_VERSION) {
startActivity(new Intent(this, FirstStartActivity.class));
}
settingsViewModel = ViewModelProviders.of(this).get(SettingsViewModel.class);
devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
deviceAdmin = new ComponentName(this, UninstallProtectionReceiver.class);
setContentView(R.layout.activity_settings);
contentView = findViewById(R.id.content_view_settings);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
secondFragmentContainer = findViewById(R.id.second_fragment_container);
Fragment settingsFragment = getSupportFragmentManager().findFragmentByTag(TAG_PREFERENCE_FRAGMENT);
if (settingsFragment == null || !UNLOCKED) {
// Main fragment doesn't exist, app just opened
// → Show lockscreen
UNLOCKED = false;
if (!MLPreferences.getPreferences(this).getString(Common.LOCKING_TYPE, "").isEmpty()) {
contentView.addView(lockscreen = new LockView(this, null), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
lockscreen.forceFocus();
// → Hide Action bar
toolbar.setTranslationY(-getResources().getDimensionPixelSize(R.dimen.toolbar_height));
} else
UNLOCKED = true;
// → Create and display settings
settingsFragment = getIntent().getAction() != null && getIntent().getAction().equals(BuildConfig.APPLICATION_ID + ".VIEW_APPS") ? new AppListFragment() : MaxLockPreferenceFragment.Screen.MAIN.getScreen();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, settingsFragment, TAG_PREFERENCE_FRAGMENT).commit();
}
ctConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient customTabsClient) {
customTabsClient.warmup(0);
ctSession = customTabsClient.newSession(new CustomTabsCallback());
if (ctSession == null)
return;
Bundle maxr1998Website = new Bundle();
maxr1998Website.putParcelable(CustomTabsService.KEY_URL, Common.MAXR1998_URI);
Bundle technoSparksProfile = new Bundle();
technoSparksProfile.putParcelable(CustomTabsService.KEY_URL, Common.TECHNO_SPARKS_URI);
ctSession.mayLaunchUrl(Common.WEBSITE_URI, null, Arrays.asList(maxr1998Website, technoSparksProfile));
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
};
String cctPackageName = CustomTabsClient.getPackageName(this, Arrays.asList("com.android.chrome", "com.chrome.beta", "com.chrome.dev", "org.mozilla.firefox", "org.mozilla.firefox_beta"));
if (cctPackageName != null) {
CustomTabsClient.bindCustomTabsService(this, cctPackageName, ctConnection);
} else
ctConnection = null;
}
use of androidx.browser.customtabs.CustomTabsCallback in project android-browser-helper by GoogleChrome.
the class TwaQualityEnforcerTest method triggerQualityEnforcement_Crash.
@Test
public void triggerQualityEnforcement_Crash() {
Runnable launchRunnable = () -> mTwaLauncher.launch(new TrustedWebActivityIntentBuilder(URL), mCustomTabsCallback, null, null);
CustomTabsSessionToken token = CustomTabsSessionToken.getSessionTokenFromIntent(getBrowserActivityWhenLaunched(launchRunnable).getIntent());
CustomTabsCallback callback = token.getCallback();
Bundle args = new Bundle();
String message = "TestMessage";
args.putString(QualityEnforcer.KEY_CRASH_REASON, message);
Bundle result = callback.extraCallbackWithResult(QualityEnforcer.CRASH, args);
assertTrue(result.getBoolean(QualityEnforcer.KEY_SUCCESS));
assertTrue(mCrashed);
}
use of androidx.browser.customtabs.CustomTabsCallback in project android-browser-helper by GoogleChrome.
the class MainActivity method onStart.
@Override
protected void onStart() {
super.onStart();
// Set up a callback that launches the intent after session was validated.
CustomTabsCallback callback = new CustomTabsCallback() {
@Override
public void onRelationshipValidationResult(int relation, @NonNull Uri requestedOrigin, boolean result, @Nullable Bundle extras) {
// Can launch custom tabs intent after session was validated as the same origin.
mExtraButton.setEnabled(true);
}
};
// Set up a connection that warms up and validates a session.
mConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(@NonNull ComponentName name, @NonNull CustomTabsClient client) {
// Create session after service connected.
mSession = client.newSession(callback);
client.warmup(0);
// Validate the session as the same origin to allow cross origin headers.
mSession.validateRelationship(CustomTabsService.RELATION_USE_AS_ORIGIN, URL, null);
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
}
};
// Add package names for other browsers that support Custom Tabs and custom headers.
List<String> packageNames = Arrays.asList("com.google.android.apps.chrome", "com.chrome.canary", "com.chrome.dev", "com.chrome.beta", "com.android.chrome");
String packageName = CustomTabsClient.getPackageName(MainActivity.this, packageNames, false);
if (packageName == null) {
Toast.makeText(getApplicationContext(), "Package name is null.", Toast.LENGTH_SHORT).show();
} else {
// Bind the custom tabs service connection.
CustomTabsClient.bindCustomTabsService(this, packageName, mConnection);
}
}
Aggregations