blob: de2709d3d7acdc36f3ef8975c4ed803c6aeee5e7 [file] [log] [blame]
Makoto Onuki0acbb142016-03-22 17:02:57 -07001/*
2 * Copyright (C) 2016 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 */
16package com.android.server.pm;
17
18import android.annotation.NonNull;
19
Makoto Onuki9da23fc2016-03-29 11:14:42 -070020import com.android.internal.util.Preconditions;
21
Makoto Onuki0acbb142016-03-22 17:02:57 -070022import org.xmlpull.v1.XmlPullParserException;
23import org.xmlpull.v1.XmlSerializer;
24
25import java.io.IOException;
26
Makoto Onuki9da23fc2016-03-29 11:14:42 -070027abstract class ShortcutPackageItem {
28 private final int mPackageUserId;
29 private final String mPackageName;
Makoto Onuki0acbb142016-03-22 17:02:57 -070030
Makoto Onuki9da23fc2016-03-29 11:14:42 -070031 private ShortcutPackageInfo mPackageInfo;
32
33 protected ShortcutPackageItem(int packageUserId, @NonNull String packageName,
34 @NonNull ShortcutPackageInfo packageInfo) {
35 mPackageUserId = packageUserId;
36 mPackageName = Preconditions.checkStringNotEmpty(packageName);
37 mPackageInfo = Preconditions.checkNotNull(packageInfo);
38 }
39
40 /**
41 * ID of the user who actually has this package running on. For {@link ShortcutPackage},
42 * this is the same thing as {@link #getOwnerUserId}, but if it's a {@link ShortcutLauncher} and
43 * {@link #getOwnerUserId} is of a work profile, then this ID could be the user who owns the
44 * profile.
45 */
46 public int getPackageUserId() {
47 return mPackageUserId;
48 }
49
50 /**
51 * ID of the user who sees the shortcuts from this instance.
52 */
53 public abstract int getOwnerUserId();
54
55 @NonNull
56 public String getPackageName() {
57 return mPackageName;
58 }
59
60 public ShortcutPackageInfo getPackageInfo() {
61 return mPackageInfo;
62 }
63
64 /**
65 * Should be only used when loading from a file.o
66 */
67 protected void replacePackageInfo(@NonNull ShortcutPackageInfo packageInfo) {
68 mPackageInfo = Preconditions.checkNotNull(packageInfo);
69 }
70
71 public void refreshPackageInfoAndSave(ShortcutService s) {
72 mPackageInfo.refresh(s, this);
73 s.scheduleSaveUser(getOwnerUserId());
74 }
75
76 public void ensureNotShadowAndSave(ShortcutService s) {
77 if (mPackageInfo.isShadow()) {
78 mPackageInfo.setShadow(false);
79 s.scheduleSaveUser(getOwnerUserId());
80 }
81 }
82
83 public abstract void saveToXml(@NonNull XmlSerializer out, boolean forBackup)
Makoto Onuki0acbb142016-03-22 17:02:57 -070084 throws IOException, XmlPullParserException;
85}