From 5a7cfb25f93652234b3222a99dba17f148829a25 Mon Sep 17 00:00:00 2001 From: shubang Date: Sat, 22 Jan 2022 18:25:28 -0800 Subject: [PATCH] TIAF: make AppLinkInfo a class Bug: 16677688 Test: mmm Change-Id: Ifb9cd66fea292f76af3551d9642dc1edc9e4d1c3 --- .../media/tv/interactive/AppLinkInfo.aidl | 19 ++ .../media/tv/interactive/AppLinkInfo.java | 234 ++++++++++++++++++ .../interactive/ITvInteractiveAppManager.aidl | 5 +- .../interactive/ITvInteractiveAppService.aidl | 5 +- .../interactive/TvInteractiveAppManager.java | 5 +- .../interactive/TvInteractiveAppService.java | 8 +- .../TvInteractiveAppManagerService.java | 17 +- 7 files changed, 275 insertions(+), 18 deletions(-) create mode 100644 media/java/android/media/tv/interactive/AppLinkInfo.aidl create mode 100644 media/java/android/media/tv/interactive/AppLinkInfo.java diff --git a/media/java/android/media/tv/interactive/AppLinkInfo.aidl b/media/java/android/media/tv/interactive/AppLinkInfo.aidl new file mode 100644 index 0000000000000..7c52d018a3d6c --- /dev/null +++ b/media/java/android/media/tv/interactive/AppLinkInfo.aidl @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media.tv.interactive; + +parcelable AppLinkInfo; \ No newline at end of file diff --git a/media/java/android/media/tv/interactive/AppLinkInfo.java b/media/java/android/media/tv/interactive/AppLinkInfo.java new file mode 100644 index 0000000000000..5cce44319e5da --- /dev/null +++ b/media/java/android/media/tv/interactive/AppLinkInfo.java @@ -0,0 +1,234 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media.tv.interactive; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.os.Parcel; +import android.os.Parcelable; + +/** + * App link information used by TV interactive app to launch Android apps. + * @hide + */ +public final class AppLinkInfo implements Parcelable { + private @NonNull String mPackageName; + private @NonNull String mClassName; + private @Nullable String mUriScheme; + private @Nullable String mUriHost; + private @Nullable String mUriPrefix; + + + /** + * Creates a new AppLinkInfo. + */ + private AppLinkInfo( + @NonNull String packageName, + @NonNull String className, + @Nullable String uriScheme, + @Nullable String uriHost, + @Nullable String uriPrefix) { + this.mPackageName = packageName; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mPackageName); + this.mClassName = className; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mClassName); + this.mUriScheme = uriScheme; + this.mUriHost = uriHost; + this.mUriPrefix = uriPrefix; + } + + /** + * Gets package name of the App link. + */ + @NonNull + public String getPackageName() { + return mPackageName; + } + + /** + * Gets package class of the App link. + */ + @NonNull + public String getClassName() { + return mClassName; + } + + /** + * Gets URI scheme of the App link. + */ + @Nullable + public String getUriScheme() { + return mUriScheme; + } + + /** + * Gets URI host of the App link. + */ + @Nullable + public String getUriHost() { + return mUriHost; + } + + /** + * Gets URI prefix of the App link. + */ + @Nullable + public String getUriPrefix() { + return mUriPrefix; + } + + @Override + public String toString() { + return "AppLinkInfo { " + + "packageName = " + mPackageName + ", " + + "className = " + mClassName + ", " + + "uriScheme = " + mUriScheme + ", " + + "uriHost = " + mUriHost + ", " + + "uriPrefix = " + mUriPrefix + + " }"; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeString(mPackageName); + dest.writeString(mClassName); + dest.writeString(mUriScheme); + dest.writeString(mUriHost); + dest.writeString(mUriPrefix); + } + + @Override + public int describeContents() { + return 0; + } + + /* package-private */ AppLinkInfo(@NonNull Parcel in) { + String packageName = in.readString(); + String className = in.readString(); + String uriScheme = in.readString(); + String uriHost = in.readString(); + String uriPrefix = in.readString(); + + this.mPackageName = packageName; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mPackageName); + this.mClassName = className; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mClassName); + this.mUriScheme = uriScheme; + this.mUriHost = uriHost; + this.mUriPrefix = uriPrefix; + } + + @NonNull + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public AppLinkInfo[] newArray(int size) { + return new AppLinkInfo[size]; + } + + @Override + public AppLinkInfo createFromParcel(@NonNull Parcel in) { + return new AppLinkInfo(in); + } + }; + + /** + * A builder for {@link AppLinkInfo} + */ + public static final class Builder { + private @NonNull String mPackageName; + private @NonNull String mClassName; + private @Nullable String mUriScheme; + private @Nullable String mUriHost; + private @Nullable String mUriPrefix; + + /** + * Creates a new Builder. + */ + public Builder( + @NonNull String packageName, + @NonNull String className) { + mPackageName = packageName; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mPackageName); + mClassName = className; + com.android.internal.util.AnnotationValidations.validate( + NonNull.class, null, mClassName); + } + + /** + * Sets package name of the App link. + */ + @NonNull + public Builder setPackageName(@NonNull String value) { + mPackageName = value; + return this; + } + + /** + * Sets app name of the App link. + */ + @NonNull + public Builder setClassName(@NonNull String value) { + mClassName = value; + return this; + } + + /** + * Sets URI scheme of the App link. + */ + @NonNull + public Builder setUriScheme(@Nullable String value) { + mUriScheme = value; + return this; + } + + /** + * Sets URI host of the App link. + */ + @NonNull + public Builder setUriHost(@Nullable String value) { + mUriHost = value; + return this; + } + + /** + * Sets URI prefix of the App link. + */ + @NonNull + public Builder setUriPrefix(@Nullable String value) { + mUriPrefix = value; + return this; + } + + /** Builds the instance. This builder should not be touched after calling this! */ + @NonNull + public AppLinkInfo build() { + AppLinkInfo o = new AppLinkInfo( + mPackageName, + mClassName, + mUriScheme, + mUriHost, + mUriPrefix); + return o; + } + } +} diff --git a/media/java/android/media/tv/interactive/ITvInteractiveAppManager.aidl b/media/java/android/media/tv/interactive/ITvInteractiveAppManager.aidl index a8ef0957286c6..aaabe342d9f16 100644 --- a/media/java/android/media/tv/interactive/ITvInteractiveAppManager.aidl +++ b/media/java/android/media/tv/interactive/ITvInteractiveAppManager.aidl @@ -20,6 +20,7 @@ import android.graphics.Rect; import android.media.tv.AdResponse; import android.media.tv.BroadcastInfoResponse; import android.media.tv.TvTrackInfo; +import android.media.tv.interactive.AppLinkInfo; import android.media.tv.interactive.ITvInteractiveAppClient; import android.media.tv.interactive.ITvInteractiveAppManagerCallback; import android.media.tv.interactive.TvInteractiveAppInfo; @@ -34,8 +35,8 @@ import android.view.Surface; interface ITvInteractiveAppManager { List getTvInteractiveAppServiceList(int userId); void prepare(String tiasId, int type, int userId); - void registerAppLinkInfo(String tiasId, in Bundle info, int userId); - void unregisterAppLinkInfo(String tiasId, in Bundle info, int userId); + void registerAppLinkInfo(String tiasId, in AppLinkInfo info, int userId); + void unregisterAppLinkInfo(String tiasId, in AppLinkInfo info, int userId); void sendAppLinkCommand(String tiasId, in Bundle command, int userId); void startInteractiveApp(in IBinder sessionToken, int userId); void stopInteractiveApp(in IBinder sessionToken, int userId); diff --git a/media/java/android/media/tv/interactive/ITvInteractiveAppService.aidl b/media/java/android/media/tv/interactive/ITvInteractiveAppService.aidl index 68fae2d96c98b..b6d518ff7242f 100644 --- a/media/java/android/media/tv/interactive/ITvInteractiveAppService.aidl +++ b/media/java/android/media/tv/interactive/ITvInteractiveAppService.aidl @@ -16,6 +16,7 @@ package android.media.tv.interactive; +import android.media.tv.interactive.AppLinkInfo; import android.media.tv.interactive.ITvInteractiveAppServiceCallback; import android.media.tv.interactive.ITvInteractiveAppSessionCallback; import android.os.Bundle; @@ -32,7 +33,7 @@ oneway interface ITvInteractiveAppService { void createSession(in InputChannel channel, in ITvInteractiveAppSessionCallback callback, in String iAppServiceId, int type); void prepare(int type); - void registerAppLinkInfo(in Bundle info); - void unregisterAppLinkInfo(in Bundle info); + void registerAppLinkInfo(in AppLinkInfo info); + void unregisterAppLinkInfo(in AppLinkInfo info); void sendAppLinkCommand(in Bundle command); } \ No newline at end of file diff --git a/media/java/android/media/tv/interactive/TvInteractiveAppManager.java b/media/java/android/media/tv/interactive/TvInteractiveAppManager.java index 15a5f823e144f..39be501a072d8 100755 --- a/media/java/android/media/tv/interactive/TvInteractiveAppManager.java +++ b/media/java/android/media/tv/interactive/TvInteractiveAppManager.java @@ -757,7 +757,8 @@ public final class TvInteractiveAppManager { * Registers app link info. * @hide */ - public void registerAppLinkInfo(@NonNull String tvIAppServiceId, @NonNull Bundle appLinkInfo) { + public void registerAppLinkInfo( + @NonNull String tvIAppServiceId, @NonNull AppLinkInfo appLinkInfo) { try { mService.registerAppLinkInfo(tvIAppServiceId, appLinkInfo, mUserId); } catch (RemoteException e) { @@ -770,7 +771,7 @@ public final class TvInteractiveAppManager { * @hide */ public void unregisterAppLinkInfo( - @NonNull String tvIAppServiceId, @NonNull Bundle appLinkInfo) { + @NonNull String tvIAppServiceId, @NonNull AppLinkInfo appLinkInfo) { try { mService.unregisterAppLinkInfo(tvIAppServiceId, appLinkInfo, mUserId); } catch (RemoteException e) { diff --git a/media/java/android/media/tv/interactive/TvInteractiveAppService.java b/media/java/android/media/tv/interactive/TvInteractiveAppService.java index c27aeb98a2edc..d599d0a609956 100755 --- a/media/java/android/media/tv/interactive/TvInteractiveAppService.java +++ b/media/java/android/media/tv/interactive/TvInteractiveAppService.java @@ -182,12 +182,12 @@ public abstract class TvInteractiveAppService extends Service { } @Override - public void registerAppLinkInfo(Bundle appLinkInfo) { + public void registerAppLinkInfo(AppLinkInfo appLinkInfo) { onRegisterAppLinkInfo(appLinkInfo); } @Override - public void unregisterAppLinkInfo(Bundle appLinkInfo) { + public void unregisterAppLinkInfo(AppLinkInfo appLinkInfo) { onUnregisterAppLinkInfo(appLinkInfo); } @@ -210,7 +210,7 @@ public abstract class TvInteractiveAppService extends Service { * Registers App link info. * @hide */ - public void onRegisterAppLinkInfo(Bundle appLinkInfo) { + public void onRegisterAppLinkInfo(AppLinkInfo appLinkInfo) { // TODO: make it abstract when unhide } @@ -218,7 +218,7 @@ public abstract class TvInteractiveAppService extends Service { * Unregisters App link info. * @hide */ - public void onUnregisterAppLinkInfo(Bundle appLinkInfo) { + public void onUnregisterAppLinkInfo(AppLinkInfo appLinkInfo) { // TODO: make it abstract when unhide } diff --git a/services/core/java/com/android/server/tv/interactive/TvInteractiveAppManagerService.java b/services/core/java/com/android/server/tv/interactive/TvInteractiveAppManagerService.java index 9ead7fe0534b0..b3649a75ee5b7 100644 --- a/services/core/java/com/android/server/tv/interactive/TvInteractiveAppManagerService.java +++ b/services/core/java/com/android/server/tv/interactive/TvInteractiveAppManagerService.java @@ -34,6 +34,7 @@ import android.media.tv.AdResponse; import android.media.tv.BroadcastInfoRequest; import android.media.tv.BroadcastInfoResponse; import android.media.tv.TvTrackInfo; +import android.media.tv.interactive.AppLinkInfo; import android.media.tv.interactive.ITvInteractiveAppClient; import android.media.tv.interactive.ITvInteractiveAppManager; import android.media.tv.interactive.ITvInteractiveAppManagerCallback; @@ -695,9 +696,9 @@ public class TvInteractiveAppManagerService extends SystemService { } @Override - public void registerAppLinkInfo(String tiasId, Bundle appLinkInfo, int userId) { + public void registerAppLinkInfo(String tiasId, AppLinkInfo appLinkInfo, int userId) { final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), - Binder.getCallingUid(), userId, "registerAppLinkInfo"); + Binder.getCallingUid(), userId, "registerAppLinkInfo: " + appLinkInfo); final long identity = Binder.clearCallingIdentity(); try { synchronized (mLock) { @@ -731,9 +732,9 @@ public class TvInteractiveAppManagerService extends SystemService { } @Override - public void unregisterAppLinkInfo(String tiasId, Bundle appLinkInfo, int userId) { + public void unregisterAppLinkInfo(String tiasId, AppLinkInfo appLinkInfo, int userId) { final int resolvedUserId = resolveCallingUserId(Binder.getCallingPid(), - Binder.getCallingUid(), userId, "unregisterAppLinkInfo"); + Binder.getCallingUid(), userId, "unregisterAppLinkInfo: " + appLinkInfo); final long identity = Binder.clearCallingIdentity(); try { synchronized (mLock) { @@ -1819,7 +1820,7 @@ public class TvInteractiveAppManagerService extends SystemService { private final ServiceConnection mConnection; private final ComponentName mComponent; private final String mIAppServiceId; - private final List> mPendingAppLinkInfo = new ArrayList<>(); + private final List> mPendingAppLinkInfo = new ArrayList<>(); private final List mPendingAppLinkCommand = new ArrayList<>(); private boolean mPendingPrepare = false; @@ -1842,7 +1843,7 @@ public class TvInteractiveAppManagerService extends SystemService { mIAppServiceId = tias; } - private void addPendingAppLink(Bundle info, boolean register) { + private void addPendingAppLink(AppLinkInfo info, boolean register) { mPendingAppLinkInfo.add(Pair.create(info, register)); } @@ -1899,10 +1900,10 @@ public class TvInteractiveAppManagerService extends SystemService { } if (!serviceState.mPendingAppLinkInfo.isEmpty()) { - for (Iterator> it = + for (Iterator> it = serviceState.mPendingAppLinkInfo.iterator(); it.hasNext(); ) { - Pair appLinkInfoPair = it.next(); + Pair appLinkInfoPair = it.next(); final long identity = Binder.clearCallingIdentity(); try { if (appLinkInfoPair.second) {