use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.
the class BluetoothTestUtils method discoverable.
/**
* Puts the local device into discoverable mode and checks to make sure that the local device
* is in discoverable mode and that the correct actions were broadcast.
*
* @param adapter The BT adapter.
*/
public void discoverable(BluetoothAdapter adapter) {
if (!adapter.isEnabled()) {
fail("discoverable() bluetooth not enabled");
}
int scanMode = adapter.getScanMode();
if (scanMode != BluetoothAdapter.SCAN_MODE_CONNECTABLE) {
return;
}
final Semaphore completionSemaphore = new Semaphore(0);
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (!BluetoothAdapter.ACTION_SCAN_MODE_CHANGED.equals(action)) {
return;
}
final int mode = intent.getIntExtra(BluetoothAdapter.EXTRA_SCAN_MODE, BluetoothAdapter.SCAN_MODE_NONE);
if (mode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
completionSemaphore.release();
}
}
};
final IntentFilter filter = new IntentFilter(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
mContext.registerReceiver(receiver, filter);
assertTrue(adapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE));
boolean success = false;
try {
success = completionSemaphore.tryAcquire(DISCOVERABLE_UNDISCOVERABLE_TIMEOUT, TimeUnit.MILLISECONDS);
writeOutput(String.format("discoverable() completed in 0 ms"));
} catch (final InterruptedException e) {
// This should never happen but just in case it does, the test will fail anyway.
}
mContext.unregisterReceiver(receiver);
if (!success) {
fail(String.format("discoverable() timeout: scanMode=%d (expected %d)", scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE));
}
}
use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.
the class BroadcastTest method testLocalReceivePermissionDenied.
public void testLocalReceivePermissionDenied() throws Exception {
setExpectedReceivers(new String[] { RECEIVER_RESULTS });
BroadcastReceiver finish = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
gotReceive(RECEIVER_RESULTS, intent);
}
};
getContext().sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_LOCAL_DENIED), null, finish, null, Activity.RESULT_CANCELED, null, null);
waitForResultOrThrow(BROADCAST_TIMEOUT);
}
use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.
the class BroadcastTest method testRemoteBroadcastPermissionDenied.
public void testRemoteBroadcastPermissionDenied() throws Exception {
setExpectedReceivers(new String[] { RECEIVER_RESULTS });
BroadcastReceiver finish = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
gotReceive(RECEIVER_RESULTS, intent);
}
};
getContext().sendOrderedBroadcast(makeBroadcastIntent(BROADCAST_REMOTE), PERMISSION_DENIED, finish, null, Activity.RESULT_CANCELED, null, null);
waitForResultOrThrow(BROADCAST_TIMEOUT);
}
use of android.content.BroadcastReceiver in project KISS by Neamar.
the class MainActivity method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
// Initialize UI
prefs = PreferenceManager.getDefaultSharedPreferences(this);
String theme = prefs.getString("theme", "light");
switch(theme) {
case "dark":
setTheme(R.style.AppThemeDark);
break;
case "transparent":
setTheme(R.style.AppThemeTransparent);
break;
case "semi-transparent":
setTheme(R.style.AppThemeSemiTransparent);
break;
case "semi-transparent-dark":
setTheme(R.style.AppThemeSemiTransparentDark);
break;
case "transparent-dark":
setTheme(R.style.AppThemeTransparentDark);
break;
}
super.onCreate(savedInstanceState);
IntentFilter intentFilter = new IntentFilter(START_LOAD);
IntentFilter intentFilterBis = new IntentFilter(LOAD_OVER);
IntentFilter intentFilterTer = new IntentFilter(FULL_LOAD_OVER);
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(LOAD_OVER)) {
updateRecords(searchEditText.getText().toString());
} else if (intent.getAction().equalsIgnoreCase(FULL_LOAD_OVER)) {
// Run GC once to free all the garbage accumulated during provider initialization
System.gc();
displayQuickFavoritesBar(true, false);
displayLoader(false);
} else if (intent.getAction().equalsIgnoreCase(START_LOAD)) {
displayLoader(true);
}
}
};
this.registerReceiver(mReceiver, intentFilter);
this.registerReceiver(mReceiver, intentFilterBis);
this.registerReceiver(mReceiver, intentFilterTer);
KissApplication.initDataHandler(this);
// Initialize preferences
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
// Do it here (before initializing the view) to make the transition as smooth as possible
if (prefs.getBoolean("force-portrait", true)) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
}
setContentView(R.layout.main);
this.list = (ListView) this.findViewById(android.R.id.list);
this.listContainer = (View) this.list.getParent();
this.listEmpty = this.findViewById(android.R.id.empty);
// Create adapter for records
this.adapter = new RecordAdapter(this, this, R.layout.item_app, new ArrayList<Result>());
this.list.setAdapter(this.adapter);
this.list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
adapter.onClick(position, v);
}
});
this.adapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
super.onChanged();
if (adapter.isEmpty()) {
listContainer.setVisibility(View.GONE);
listEmpty.setVisibility(View.VISIBLE);
} else {
listContainer.setVisibility(View.VISIBLE);
listEmpty.setVisibility(View.GONE);
}
}
});
registerLongClickOnFavorites();
searchEditText = (EditText) findViewById(R.id.searchEditText);
// Listen to changes
searchEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
// Auto left-trim text.
if (s.length() > 0 && s.charAt(0) == ' ')
s.delete(0, 1);
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
String text = s.toString();
adjustInputType(text);
updateRecords(text);
displayClearOnInput();
}
});
// On validate, launch first record
searchEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
RecordAdapter adapter = ((RecordAdapter) list.getAdapter());
adapter.onClick(adapter.getCount() - 1, v);
return true;
}
});
kissBar = findViewById(R.id.main_kissbar);
favoritesKissBar = findViewById(R.id.favoritesKissBar);
menuButton = findViewById(R.id.menuButton);
registerForContextMenu(menuButton);
this.list.setLongClickable(true);
this.list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View v, int pos, long id) {
((RecordAdapter) parent.getAdapter()).onLongClick(pos, v);
return true;
}
});
this.hider = new KeyboardScrollHider(this, (BlockableListView) this.list, (BottomPullEffectView) this.findViewById(R.id.listEdgeEffect));
this.hider.start();
// Check whether user enabled spell check and adjust input type accordingly
searchEditTextWorkaround = prefs.getBoolean("enable-keyboard-workaround", false);
adjustInputType(null);
//enable/disable phone/sms broadcast receiver
PackageManagerUtils.enableComponent(this, IncomingSmsHandler.class, prefs.getBoolean("enable-sms-history", false));
PackageManagerUtils.enableComponent(this, IncomingCallHandler.class, prefs.getBoolean("enable-phone-history", false));
// Hide the "X" after the text field, instead displaying the menu button
displayClearOnInput();
UiTweaks.updateThemePrimaryColor(this);
UiTweaks.tintResources(this);
}
use of android.content.BroadcastReceiver in project android_frameworks_base by DirtyUnicorns.
the class DevicePolicyManagerService method choosePrivateKeyAlias.
@Override
public void choosePrivateKeyAlias(final int uid, final Uri uri, final String alias, final IBinder response) {
// Caller UID needs to be trusted, so we restrict this method to SYSTEM_UID callers.
if (!isCallerWithSystemUid()) {
return;
}
final UserHandle caller = mInjector.binderGetCallingUserHandle();
// If there is a profile owner, redirect to that; otherwise query the device owner.
ComponentName aliasChooser = getProfileOwner(caller.getIdentifier());
if (aliasChooser == null && caller.isSystem()) {
ActiveAdmin deviceOwnerAdmin = getDeviceOwnerAdminLocked();
if (deviceOwnerAdmin != null) {
aliasChooser = deviceOwnerAdmin.info.getComponent();
}
}
if (aliasChooser == null) {
sendPrivateKeyAliasResponse(null, response);
return;
}
Intent intent = new Intent(DeviceAdminReceiver.ACTION_CHOOSE_PRIVATE_KEY_ALIAS);
intent.setComponent(aliasChooser);
intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_SENDER_UID, uid);
intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_URI, uri);
intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_ALIAS, alias);
intent.putExtra(DeviceAdminReceiver.EXTRA_CHOOSE_PRIVATE_KEY_RESPONSE, response);
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
final long id = mInjector.binderClearCallingIdentity();
try {
mContext.sendOrderedBroadcastAsUser(intent, caller, null, new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String chosenAlias = getResultData();
sendPrivateKeyAliasResponse(chosenAlias, response);
}
}, null, Activity.RESULT_OK, null, null);
} finally {
mInjector.binderRestoreCallingIdentity(id);
}
}
Aggregations