Launch new Home app when selecting Home app in Settings

Launches the newly selected Home app when it has been selected in
Default Home app settings. This CL makes the change take effect
immediately, instead of when the Home button is pressed.

Bug: 70697830
Test: make RunSettingsRoboTests
Test: Manual - Change default home app in Settings
Change-Id: If7e2956bc6f8ddba0a7e8da48a0d38e3936c57e9
This commit is contained in:
rongrong.x.gao
2017-03-02 17:29:34 +08:00
committed by Takamasa Kuramitsu
parent 6b1ff7073a
commit b573e23b48
2 changed files with 13 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.applications.defaultapps;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
@@ -104,6 +105,14 @@ public class DefaultHomePicker extends DefaultAppPickerFragment {
IntentFilter.MATCH_CATEGORY_EMPTY, IntentFilter.MATCH_CATEGORY_EMPTY,
allComponents.toArray(new ComponentName[0]), allComponents.toArray(new ComponentName[0]),
component); component);
// Launch the new Home app so the change is immediately visible even if
// the Home button is not pressed.
final Context context = getContext();
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
return true; return true;
} }
return false; return false;

View File

@@ -73,6 +73,7 @@ public class DefaultHomePickerTest {
@Mock @Mock
private PackageManager mPackageManager; private PackageManager mPackageManager;
private Context mContext;
private DefaultHomePicker mPicker; private DefaultHomePicker mPicker;
@Before @Before
@@ -85,7 +86,8 @@ public class DefaultHomePickerTest {
mPicker.onAttach((Context) mActivity); mPicker.onAttach((Context) mActivity);
ReflectionHelpers.setField(mPicker, "mPm", mPackageManagerWrapper); ReflectionHelpers.setField(mPicker, "mPm", mPackageManagerWrapper);
doReturn(RuntimeEnvironment.application).when(mPicker).getContext(); mContext = spy(RuntimeEnvironment.application);
doReturn(mContext).when(mPicker).getContext();
} }
@Test @Test
@@ -94,6 +96,7 @@ public class DefaultHomePickerTest {
verify(mPackageManagerWrapper).replacePreferredActivity(any(IntentFilter.class), verify(mPackageManagerWrapper).replacePreferredActivity(any(IntentFilter.class),
anyInt(), any(ComponentName[].class), any(ComponentName.class)); anyInt(), any(ComponentName[].class), any(ComponentName.class));
verify(mContext).startActivity(any());
} }
@Test @Test