Merge "Prevent ClassCastException" into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c8f32a43b0
@@ -345,8 +345,12 @@ public class TileServices extends IQSService.Stub {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (TileService.ACTION_REQUEST_LISTENING.equals(intent.getAction())) {
|
||||
requestListening(
|
||||
(ComponentName) intent.getParcelableExtra(Intent.EXTRA_COMPONENT_NAME));
|
||||
try {
|
||||
ComponentName c = intent.getParcelableExtra(Intent.EXTRA_COMPONENT_NAME);
|
||||
requestListening(c);
|
||||
} catch (ClassCastException ex) {
|
||||
Log.e(TAG, "Bad component name", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -27,7 +27,9 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -142,6 +144,16 @@ public class TileServicesTest extends SysuiTestCase {
|
||||
assertTrue(captor.getValue().hasAction(TileService.ACTION_REQUEST_LISTENING));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadComponentName_doesntCrash() {
|
||||
ArgumentCaptor<BroadcastReceiver> captor = ArgumentCaptor.forClass(BroadcastReceiver.class);
|
||||
verify(mBroadcastDispatcher).registerReceiver(captor.capture(), any(), any(), eq(
|
||||
UserHandle.ALL));
|
||||
Intent intent = new Intent(TileService.ACTION_REQUEST_LISTENING)
|
||||
.putExtra(Intent.EXTRA_COMPONENT_NAME, "abc");
|
||||
captor.getValue().onReceive(mContext, intent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecalculateBindAllowance() {
|
||||
// Add some fake tiles.
|
||||
|
||||
Reference in New Issue
Block a user