• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.security.cts.CVE_2023_35676;
18 
19 import android.app.Notification;
20 import android.app.PendingIntent;
21 import android.app.contentsuggestions.ClassificationsRequest;
22 import android.app.contentsuggestions.ContentClassification;
23 import android.app.contentsuggestions.ContentSelection;
24 import android.app.contentsuggestions.ContentSuggestionsManager;
25 import android.app.contentsuggestions.SelectionsRequest;
26 import android.content.Intent;
27 import android.graphics.Bitmap;
28 import android.os.Bundle;
29 
30 import com.android.internal.app.PlatLogoActivity;
31 
32 import com.google.android.apps.miphone.aiai.matchmaker.overview.api.generatedv2.EntitiesData;
33 import com.google.android.apps.miphone.aiai.matchmaker.overview.api.generatedv2.SuggestParcelables;
34 
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.List;
38 
39 public class ContentSuggestionsService
40         extends android.service.contentsuggestions.ContentSuggestionsService {
41 
42     @Override
onProcessContextImage(int taskId, Bitmap contextImage, Bundle extras)43     public void onProcessContextImage(int taskId, Bitmap contextImage, Bundle extras) {}
44 
45     @Override
onSuggestContentSelections( SelectionsRequest request, ContentSuggestionsManager.SelectionsCallback callback)46     public void onSuggestContentSelections(
47             SelectionsRequest request, ContentSuggestionsManager.SelectionsCallback callback) {
48         Notification.Action action =
49                 new Notification.Action.Builder(
50                                 null,
51                                 "title",
52                                 PendingIntent.getActivity(
53                                         this,
54                                         0 /* request code */,
55                                         new Intent()
56                                                 .setClassName(
57                                                         "android",
58                                                         PlatLogoActivity.class.getName()),
59                                         PendingIntent.FLAG_MUTABLE))
60                         .build();
61         ArrayList<Notification.Action> actions = new ArrayList<>();
62         actions.add(action);
63 
64         Bundle extras = new Bundle();
65         extras.putParcelableArrayList("ScreenshotNotificationActions", actions);
66         List<ContentSelection> contentSelectionList = new ArrayList<>();
67         contentSelectionList.add(new ContentSelection(getString(R.string.placeHolderId), extras));
68         callback.onContentSelectionsAvailable(0 /* statusCode */, contentSelectionList);
69     }
70 
71     @Override
onClassifyContentSelections( ClassificationsRequest request, ContentSuggestionsManager.ClassificationsCallback callback)72     public void onClassifyContentSelections(
73             ClassificationsRequest request,
74             ContentSuggestionsManager.ClassificationsCallback callback) {
75 
76         Bundle actionBundle = new Bundle();
77         actionBundle.putString(getString(R.string.id), getString(R.string.actionId));
78         actionBundle.putString(getString(R.string.displayName), getString(R.string.cve_button));
79         actionBundle.putString(getString(R.string.fullDisplayName), "actionFullDisplayName");
80 
81         Bundle actionGroupBundle = new Bundle();
82         actionGroupBundle.putString(getString(R.string.id), "groupID");
83         actionGroupBundle.putString(getString(R.string.displayName), "groupDisplayName");
84         actionGroupBundle.putBundle(getString(R.string.mainAction), actionBundle);
85         ArrayList<Bundle> actionsList = new ArrayList<>();
86         actionsList.add(actionGroupBundle);
87 
88         Bundle entityBundle = new Bundle();
89         entityBundle.putParcelableArrayList(getString(R.string.actions), actionsList);
90         entityBundle.putString(getString(R.string.searchQueryHint), "");
91         SuggestParcelables.Entity entity = new SuggestParcelables.Entity(entityBundle);
92 
93         SuggestParcelables.Entities entities = new SuggestParcelables.Entities();
94         entities.entities = new ArrayList();
95         entities.entities.add(entity);
96 
97         Bundle extraInfoBundle = new Bundle();
98         extraInfoBundle.putBoolean(getString(R.string.containsPendingIntents), true);
99         extraInfoBundle.putBoolean(getString(R.string.containsBitmaps), true);
100         entities.extrasInfo = new SuggestParcelables.ExtrasInfo(extraInfoBundle);
101 
102         HashMap pendingIntentMap = new HashMap<>();
103         PendingIntent pi =
104                 PendingIntent.getActivity(
105                         this,
106                         0 /* request code */,
107                         new Intent().setClassName("android", PlatLogoActivity.class.getName()),
108                         PendingIntent.FLAG_MUTABLE);
109         pendingIntentMap.put(getString(R.string.actionId), pi);
110 
111         HashMap bitmapMap = new HashMap<>();
112         bitmapMap.put(
113                 getString(R.string.actionId),
114                 Bitmap.createBitmap(
115                         50 /* width */, 50 /* height */, Bitmap.Config.ARGB_8888 /* config */));
116 
117         EntitiesData entitiesData = new EntitiesData(entities, bitmapMap, pendingIntentMap);
118         Bundle extras = new Bundle();
119         extras.putParcelable("EntitiesData", entitiesData);
120         List<ContentClassification> contentSelectionList = new ArrayList<>();
121         contentSelectionList.add(
122                 new ContentClassification(getString(R.string.placeHolderId), extras));
123         callback.onContentClassificationsAvailable(0, contentSelectionList);
124     }
125 
126     @Override
onNotifyInteraction(String requestId, Bundle interaction)127     public void onNotifyInteraction(String requestId, Bundle interaction) {}
128 }
129