diff options
author | Szu-An <szuanlu@google.com> | 2023-01-06 21:02:20 +0800 |
---|---|---|
committer | Szu-An <szuanlu@google.com> | 2023-01-09 11:44:56 +0800 |
commit | 61fe46ffa4912b7d18e1d59e67bb95f13fb33d59 (patch) | |
tree | 16cb64be83c7ee60cb16f8a37a5e239a444a9d54 /src/com | |
parent | a33753c5c04645fdd4f17792187b1c0fc0875908 (diff) | |
download | TV-61fe46ffa4912b7d18e1d59e67bb95f13fb33d59.tar.gz |
enable device to customize setup activity via RRO
Device makers can provide an input id to setup activity
package and class name mapping table to LiveTv via RRO.
LiveTv launches the overlay setup activity instead and
fallbacks to the setup activity defined in TIS.
Bug: 264504967
Bug: 258580153
Test: m, boot Falcon, launch LiveTv check below
Test: without valid overlay, Intent creation fallback to existed flow
Test: with valid overlay, Intent can launch overlay setup activity
Change-Id: I7563d70753fde94809e934285e98efd4a7595cf4
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/tv/MainActivity.java | 2 | ||||
-rw-r--r-- | src/com/android/tv/onboarding/OnboardingActivity.java | 2 | ||||
-rw-r--r-- | src/com/android/tv/setup/SystemSetupActivity.java | 3 | ||||
-rw-r--r-- | src/com/android/tv/util/SetupUtils.java | 50 |
4 files changed, 54 insertions, 3 deletions
diff --git a/src/com/android/tv/MainActivity.java b/src/com/android/tv/MainActivity.java index 432f2e00..1f2fd027 100644 --- a/src/com/android/tv/MainActivity.java +++ b/src/com/android/tv/MainActivity.java @@ -1162,7 +1162,7 @@ public class MainActivity extends Activity * @param calledByPopup If true, startSetupActivity is invoked from the setup fragment. */ public void startSetupActivity(TvInputInfo input, boolean calledByPopup) { - Intent intent = CommonUtils.createSetupIntent(input); + Intent intent = mSetupUtils.createSetupIntent(this, input); if (intent == null) { Toast.makeText(this, R.string.msg_no_setup_activity, Toast.LENGTH_SHORT).show(); return; diff --git a/src/com/android/tv/onboarding/OnboardingActivity.java b/src/com/android/tv/onboarding/OnboardingActivity.java index dd386d81..0ce5d931 100644 --- a/src/com/android/tv/onboarding/OnboardingActivity.java +++ b/src/com/android/tv/onboarding/OnboardingActivity.java @@ -193,7 +193,7 @@ public class OnboardingActivity extends SetupActivity { params.getString( SetupSourcesFragment.ACTION_PARAM_KEY_INPUT_ID); TvInputInfo input = mInputManager.getTvInputInfo(inputId); - Intent intent = CommonUtils.createSetupIntent(input); + Intent intent = mSetupUtils.createSetupIntent(this, input); if (intent == null) { Toast.makeText( this, diff --git a/src/com/android/tv/setup/SystemSetupActivity.java b/src/com/android/tv/setup/SystemSetupActivity.java index 7bf04692..b39ac4ea 100644 --- a/src/com/android/tv/setup/SystemSetupActivity.java +++ b/src/com/android/tv/setup/SystemSetupActivity.java @@ -53,6 +53,7 @@ public class SystemSetupActivity extends SetupActivity { private static final int REQUEST_CODE_START_SETUP_ACTIVITY = 1; @Inject TvInputManagerHelper mInputManager; + @Inject SetupUtils mSetupUtils; @Inject UiFlags mUiFlags; @Override @@ -97,7 +98,7 @@ public class SystemSetupActivity extends SetupActivity { params.getString( SetupSourcesFragment.ACTION_PARAM_KEY_INPUT_ID); TvInputInfo input = mInputManager.getTvInputInfo(inputId); - Intent intent = CommonUtils.createSetupIntent(input); + Intent intent = mSetupUtils.createSetupIntent(this, input); if (intent == null) { Toast.makeText( this, diff --git a/src/com/android/tv/util/SetupUtils.java b/src/com/android/tv/util/SetupUtils.java index 52b3e3e8..aaee1047 100644 --- a/src/com/android/tv/util/SetupUtils.java +++ b/src/com/android/tv/util/SetupUtils.java @@ -31,14 +31,18 @@ import android.support.annotation.UiThread; import android.text.TextUtils; import android.util.ArraySet; import android.util.Log; +import com.android.tv.R; import com.android.tv.TvSingletons; import com.android.tv.common.SoftPreconditions; import com.android.tv.common.dagger.annotations.ApplicationContext; import com.android.tv.common.singletons.HasTvInputId; +import com.android.tv.common.util.CommonUtils; import com.android.tv.data.ChannelDataManager; import com.android.tv.data.api.Channel; import com.android.tv.tunerinputcontroller.BuiltInTunerManager; import com.google.common.base.Optional; + +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -362,6 +366,52 @@ public class SetupUtils { } /** + * Create a Intent to launch setup activity for {@code inputId}. The setup activity defined + * in the overlayable resources precedes the one defined in the corresponding TV input service. + */ + @Nullable + public Intent createSetupIntent(Context context, TvInputInfo input) { + String[] componentStrings = context.getResources() + .getStringArray(R.array.setup_ComponentNames); + + if (componentStrings != null) { + for (String component : componentStrings) { + String[] split = component.split("#"); + if (split.length != 2) { + Log.w(TAG, "Invalid component item: " + Arrays.toString(split)); + continue; + } + + final String inputId = split[0].trim(); + if (inputId.equals(input.getId())) { + final String flattenedComponentName = split[1].trim(); + final ComponentName componentName = ComponentName + .unflattenFromString(flattenedComponentName); + if (componentName == null) { + Log.w(TAG, "Failed to unflatten component: " + flattenedComponentName); + continue; + } + + final Intent overlaySetupIntent = new Intent(Intent.ACTION_MAIN); + overlaySetupIntent.setComponent(componentName); + overlaySetupIntent.putExtra(TvInputInfo.EXTRA_INPUT_ID, inputId); + + PackageManager pm = context.getPackageManager(); + if (overlaySetupIntent.resolveActivityInfo(pm, 0) == null) { + Log.w(TAG, "unable to find component" + flattenedComponentName); + continue; + } + + Log.i(TAG, "overlay input id: " + inputId + + " to setup activity: " + flattenedComponentName); + return CommonUtils.createSetupIntent(overlaySetupIntent, inputId); + } + } + } + return CommonUtils.createSetupIntent(input); + } + + /** * Called when an setup is done. Once it is called, {@link #isSetupDone} returns {@code true} * for {@code inputId}. */ |