1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.car.projection; 18 19 import android.annotation.IntDef; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.SystemApi; 23 import android.app.ActivityOptions; 24 import android.content.ComponentName; 25 import android.os.Bundle; 26 27 import java.lang.annotation.Retention; 28 import java.lang.annotation.RetentionPolicy; 29 30 /** 31 * This class holds OEM customization for projection receiver app. It is created by Car Service. 32 * 33 * @hide 34 */ 35 @SystemApi 36 public class ProjectionOptions { 37 private static final String KEY_PREFIX = "android.car.projection."; 38 39 /** Immersive full screen mode (all system bars are hidden) */ 40 public static final int UI_MODE_FULL_SCREEN = 0; 41 42 /** Show status and navigation bars. */ 43 public static final int UI_MODE_BLENDED = 1; 44 45 private static final int UI_MODE_DEFAULT = UI_MODE_FULL_SCREEN; 46 47 /** @hide */ 48 @IntDef({UI_MODE_FULL_SCREEN, UI_MODE_BLENDED}) 49 @Retention(RetentionPolicy.SOURCE) 50 public @interface ProjectionUiMode {} 51 52 private static final String KEY_ACTIVITY_OPTIONS = KEY_PREFIX + "activityOptions"; 53 private static final String KEY_UI_MODE = KEY_PREFIX + "systemUiFlags"; 54 private static final String KEY_CONSENT_ACTIVITY = KEY_PREFIX + "consentActivity"; 55 56 private final ActivityOptions mActivityOptions; 57 private final int mUiMode; 58 private final ComponentName mConsentActivity; 59 60 /** 61 * Creates new instance for given {@code Bundle} 62 * 63 * @param bundle contains OEM specific information 64 */ ProjectionOptions(Bundle bundle)65 public ProjectionOptions(Bundle bundle) { 66 Bundle activityOptionsBundle = bundle.getBundle(KEY_ACTIVITY_OPTIONS); 67 mActivityOptions = activityOptionsBundle != null 68 ? new ActivityOptions(activityOptionsBundle) : null; 69 mUiMode = bundle.getInt(KEY_UI_MODE, UI_MODE_DEFAULT); 70 mConsentActivity = bundle.getParcelable(KEY_CONSENT_ACTIVITY); 71 } 72 ProjectionOptions(Builder builder)73 private ProjectionOptions(Builder builder) { 74 mActivityOptions = builder.mActivityOptions; 75 mUiMode = builder.mUiMode; 76 mConsentActivity = builder.mConsentActivity; 77 } 78 79 /** 80 * Returns combination of flags from View.SYSTEM_UI_FLAG_* which will be used by projection 81 * receiver app during rendering. 82 */ getUiMode()83 public @ProjectionUiMode int getUiMode() { 84 return mUiMode; 85 } 86 87 /** 88 * Returns {@link ActivityOptions} that needs to be applied when launching projection activity 89 */ getActivityOptions()90 public @Nullable ActivityOptions getActivityOptions() { 91 return mActivityOptions; 92 } 93 94 /** 95 * Returns package/activity name of the consent activity provided by OEM which needs to be shown 96 * for all mobile devices unless user accepted the consent. 97 * 98 * <p>If the method returns null then consent dialog should not be shown. 99 */ getConsentActivity()100 public @Nullable ComponentName getConsentActivity() { 101 return mConsentActivity; 102 } 103 104 /** Converts current object to {@link Bundle} */ toBundle()105 public @NonNull Bundle toBundle() { 106 Bundle bundle = new Bundle(); 107 if (mActivityOptions != null) { 108 bundle.putBundle(KEY_ACTIVITY_OPTIONS, mActivityOptions.toBundle()); 109 } 110 bundle.putParcelable(KEY_CONSENT_ACTIVITY, mConsentActivity); 111 if (mUiMode != UI_MODE_DEFAULT) { 112 bundle.putInt(KEY_UI_MODE, mUiMode); 113 } 114 return bundle; 115 } 116 117 /** @hide */ builder()118 public static Builder builder() { 119 return new Builder(); 120 } 121 122 /** @hide */ 123 public static class Builder { 124 private ActivityOptions mActivityOptions; 125 private int mUiMode = UI_MODE_DEFAULT; 126 private ComponentName mConsentActivity; 127 128 /** Sets {@link ActivityOptions} to launch projection activity. */ setProjectionActivityOptions(ActivityOptions activityOptions)129 public Builder setProjectionActivityOptions(ActivityOptions activityOptions) { 130 mActivityOptions = activityOptions; 131 return this; 132 } 133 134 /** Set UI for projection activity. It can be one of {@code UI_MODE_*} constants. */ setUiMode(@rojectionUiMode int uiMode)135 public Builder setUiMode(@ProjectionUiMode int uiMode) { 136 mUiMode = uiMode; 137 return this; 138 } 139 140 /** Sets consent activity which will be shown before starting projection. */ setConsentActivity(ComponentName consentActivity)141 public Builder setConsentActivity(ComponentName consentActivity) { 142 mConsentActivity = consentActivity; 143 return this; 144 } 145 146 /** Creates an instance of {@link android.car.projection.ProjectionOptions} */ build()147 public ProjectionOptions build() { 148 return new ProjectionOptions(this); 149 } 150 } 151 152 /** @hide */ 153 @Override toString()154 public String toString() { 155 return toBundle().toString(); 156 } 157 } 158