Merge "Prevent ClassCastException" into sc-v2-dev am: c8f32a43b0
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16249682 Change-Id: Ib95dabfec889cb159fa736c196aecc6d4888cb54
This commit is contained in:
@@ -345,8 +345,12 @@ public class TileServices extends IQSService.Stub {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (TileService.ACTION_REQUEST_LISTENING.equals(intent.getAction())) {
|
if (TileService.ACTION_REQUEST_LISTENING.equals(intent.getAction())) {
|
||||||
requestListening(
|
try {
|
||||||
(ComponentName) intent.getParcelableExtra(Intent.EXTRA_COMPONENT_NAME));
|
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.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
@@ -142,6 +144,16 @@ public class TileServicesTest extends SysuiTestCase {
|
|||||||
assertTrue(captor.getValue().hasAction(TileService.ACTION_REQUEST_LISTENING));
|
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
|
@Test
|
||||||
public void testRecalculateBindAllowance() {
|
public void testRecalculateBindAllowance() {
|
||||||
// Add some fake tiles.
|
// Add some fake tiles.
|
||||||
|
|||||||
Reference in New Issue
Block a user