Skip to content

Commit f63bc88

Browse files
committed
Add install things
1 parent 4cdce52 commit f63bc88

File tree

34 files changed

+954
-128
lines changed

34 files changed

+954
-128
lines changed

examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter

+2
Original file line numberDiff line numberDiff line change
@@ -5264,6 +5264,8 @@ cluster ApplicationLauncher = 1292 {
52645264
kSuccess = 0;
52655265
kAppNotAvailable = 1;
52665266
kSystemBusy = 2;
5267+
kStatusPending = 3;
5268+
kStatusInstalling = 4;
52675269
}
52685270

52695271
bitmap Feature : bitmap32 {

examples/placeholder/linux/apps/app1/config.matter

+4
Original file line numberDiff line numberDiff line change
@@ -7895,6 +7895,8 @@ cluster ApplicationLauncher = 1292 {
78957895
kSuccess = 0;
78967896
kAppNotAvailable = 1;
78977897
kSystemBusy = 2;
7898+
kStatusPending = 3;
7899+
kStatusInstalling = 4;
78987900
}
78997901

79007902
bitmap Feature : bitmap32 {
@@ -7954,6 +7956,8 @@ cluster ApplicationLauncher = 1292 {
79547956
kSuccess = 0;
79557957
kAppNotAvailable = 1;
79567958
kSystemBusy = 2;
7959+
kStatusPending = 3;
7960+
kStatusInstalling = 4;
79577961
}
79587962

79597963
bitmap Feature : bitmap32 {

examples/placeholder/linux/apps/app2/config.matter

+4
Original file line numberDiff line numberDiff line change
@@ -7852,6 +7852,8 @@ cluster ApplicationLauncher = 1292 {
78527852
kSuccess = 0;
78537853
kAppNotAvailable = 1;
78547854
kSystemBusy = 2;
7855+
kStatusPending = 3;
7856+
kStatusInstalling = 4;
78557857
}
78567858

78577859
bitmap Feature : bitmap32 {
@@ -7911,6 +7913,8 @@ cluster ApplicationLauncher = 1292 {
79117913
kSuccess = 0;
79127914
kAppNotAvailable = 1;
79137915
kSystemBusy = 2;
7916+
kStatusPending = 3;
7917+
kStatusInstalling = 4;
79147918
}
79157919

79167920
bitmap Feature : bitmap32 {

examples/tv-app/android/App/.idea/codeStyles/Project.xml

+117
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/tv-app/android/App/.idea/codeStyles/codeStyleConfig.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/tv-app/android/App/content-app/src/main/java/com/example/contentapp/CommandResponseHolder.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.example.contentapp;
22

3+
import android.content.ContentResolver;
4+
import android.content.Context;
5+
import android.provider.Settings;
36
import android.util.Log;
47
import com.matter.tv.app.api.Clusters;
58
import java.util.HashMap;
@@ -10,6 +13,7 @@ public class CommandResponseHolder {
1013
private Map<Long, Map<Long, String>> responseValues = new HashMap<>();
1114
private static final String TAG = "CommandResponseHolder";
1215
private static final Long DEFAULT_COMMAND = -1L;
16+
private ContentResolver contentResolver;
1317

1418
private static CommandResponseHolder instance = new CommandResponseHolder();
1519

@@ -31,6 +35,7 @@ private CommandResponseHolder() {
3135
Clusters.AccountLogin.Id,
3236
Clusters.AccountLogin.Commands.GetSetupPIN.ID,
3337
"{\"0\":\"20202021\"}");
38+
// "{\"0\":\""+ Settings.Secure.getInt(contentResolver, "matter_pin_code", 20202021) +"\"}");
3439
};
3540

3641
public static CommandResponseHolder getInstance() {

examples/tv-app/android/App/platform-app/build.gradle

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ android {
4747
aidl.srcDirs = ['../common-api/src/main/aidl']
4848

4949
// uncomment this code to debug
50-
// java.srcDirs = [
51-
// 'src/main/java',
52-
// '../common-api/src/main/java',
53-
// '../../third_party/connectedhomeip/src/setup_payload/java/src',
54-
// '../../third_party/connectedhomeip/src/platform/android/java',
55-
// '../../third_party/connectedhomeip/src/app/server/java/src/',
56-
// '../../java/src',
57-
// ]
50+
java.srcDirs = [
51+
'src/main/java',
52+
'../common-api/src/main/java',
53+
'../../third_party/connectedhomeip/src/setup_payload/java/src',
54+
'../../third_party/connectedhomeip/src/platform/android/java',
55+
'../../third_party/connectedhomeip/src/app/server/java/src/',
56+
'../../java/src',
57+
]
5858
}
5959
}
6060
buildFeatures {

examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MainActivity.java

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import com.matter.tv.server.fragments.ContentAppFragment;
1212
import com.matter.tv.server.fragments.QrCodeFragment;
1313
import com.matter.tv.server.fragments.TerminalFragment;
14+
import com.matter.tv.server.utils.InstallationObserver;
15+
1416
import java.util.LinkedHashMap;
1517

1618
public class MainActivity extends AppCompatActivity {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package com.matter.tv.server.handlers;
2+
3+
import android.content.Context;
4+
import android.content.pm.PackageManager;
5+
import android.util.Log;
6+
7+
import androidx.lifecycle.LiveData;
8+
import androidx.lifecycle.Observer;
9+
10+
import com.matter.tv.server.tvapp.Application;
11+
import com.matter.tv.server.tvapp.ApplicationLauncherManager;
12+
import com.matter.tv.server.tvapp.LauncherResponse;
13+
import com.matter.tv.server.utils.EndpointsDataStore;
14+
import com.matter.tv.server.utils.InstallationObserver;
15+
16+
import java.util.HashMap;
17+
import java.util.Map;
18+
import java.util.Objects;
19+
20+
public class ApplicationLauncherManagerImpl implements ApplicationLauncherManager {
21+
22+
private static final String TAG = "ApplicationLauncherService";
23+
24+
private volatile boolean registered = false;
25+
private PackageManager packageManager;
26+
private EndpointsDataStore endpointsDataStore;
27+
28+
/**
29+
* Hash Map of packageName & Install Status
30+
*/
31+
private Map<String, InstallationObserver.InstallStatus> lastReceivedInstallationStatus = new HashMap<>();
32+
33+
private LiveData<InstallationObserver.InstallState> installStateLiveData;
34+
35+
public ApplicationLauncherManagerImpl(Context context) {
36+
packageManager = context.getPackageManager();
37+
endpointsDataStore = EndpointsDataStore.getInstance(context);
38+
registerSelf(context);
39+
}
40+
41+
// Add list of apps with latest install statuses - DONE
42+
// Add list of installed apps - DONE
43+
// Add list of installed apps that support Matter
44+
// Store all of the list using Shared pref
45+
// Load the stored lists, by asking shared pref
46+
47+
private final Observer<InstallationObserver.InstallState> installStateObserver = state -> {
48+
lastReceivedInstallationStatus.put(state.getAppPackageName(), state.getStatus());
49+
switch (state.getStatus()) {
50+
51+
case IN_PROGRESS:
52+
// Installation is in progress
53+
Log.d(TAG, "Installation of " + state.getAppPackageName() + " in progress");
54+
break;
55+
case SUCCEEDED:
56+
// Installation succeeded
57+
Log.d(TAG, "Installation of " + state.getAppPackageName() + " succeeded");
58+
break;
59+
case FAILED:
60+
// Installation failed
61+
Log.d(TAG, "Installation of " + state.getAppPackageName() + " failed");
62+
break;
63+
}
64+
};
65+
66+
private void stopObservingInstallations() {
67+
if (installStateLiveData != null) {
68+
Log.d("InstallationObserver", "Stopped Observing");
69+
installStateLiveData.removeObserver(installStateObserver);
70+
}
71+
}
72+
73+
public void unregister() {
74+
stopObservingInstallations();
75+
}
76+
77+
private void registerSelf(Context context) {
78+
if (registered) {
79+
Log.i(TAG, "Package update receiver for matter already registered");
80+
return;
81+
} else {
82+
registered = true;
83+
}
84+
Log.i(TAG, "Registered the matter package updates receiver");
85+
86+
installStateLiveData = InstallationObserver.installationStates(context);
87+
installStateLiveData.observeForever(installStateObserver);
88+
Log.d(TAG, "Started Observing package installations");
89+
}
90+
91+
@Override
92+
public int[] getCatalogList() {
93+
Log.i(TAG, "Get Catalog List");
94+
return new int[0];
95+
}
96+
97+
@Override
98+
public LauncherResponse launchApp(Application app, String data) {
99+
Log.i(TAG, "Launch app id:" + app.applicationId + " cid:" + app.catalogVendorId + " data:" + data);
100+
101+
int status = 0;
102+
String responseData = "";
103+
104+
boolean matterAppEnabledIsInstalled = endpointsDataStore.getAllPersistedContentApps().containsKey(app.applicationId);
105+
boolean appIsInstalled = InstallationObserver.getInstalledPackages(packageManager).contains(app.applicationId);
106+
boolean isAppInstalling = Objects.equals(lastReceivedInstallationStatus.get(app.applicationId), InstallationObserver.InstallStatus.IN_PROGRESS);
107+
boolean appInstallFailed = Objects.equals(lastReceivedInstallationStatus.get(app.applicationId), InstallationObserver.InstallStatus.FAILED);
108+
109+
110+
if (!matterAppEnabledIsInstalled && appIsInstalled) {
111+
Log.i(TAG, "Matter enabled app is not installed, but app is installed. Launching app's install page");
112+
status = LauncherResponse.STATUS_PENDING;
113+
responseData = "App is installed, try updating";
114+
// TODO: Launch App Install Page
115+
116+
} else if (!matterAppEnabledIsInstalled && !appIsInstalled) {
117+
Log.i(TAG, "Matter enabled app is not installed and app is not installed. Launching app's install page");
118+
if (isAppInstalling) {
119+
Log.i(TAG, "App is installing");
120+
status = LauncherResponse.STATUS_INSTALLING;
121+
} else {
122+
status = LauncherResponse.STATUS_PENDING;
123+
if (appInstallFailed) {
124+
responseData = "App install failed. Try again";
125+
}
126+
}
127+
// TODO: Launch App Install Page
128+
129+
} else if (matterAppEnabledIsInstalled && appIsInstalled) {
130+
Log.i(TAG, "Launching the app");
131+
status = LauncherResponse.STATUS_SUCCESS;
132+
// TODO: Launch App
133+
}
134+
135+
return new LauncherResponse(status, responseData);
136+
}
137+
138+
@Override
139+
public LauncherResponse stopApp(Application app) {
140+
Log.i(TAG, "Stop app id:" + app.applicationId + " cid:" + app.catalogVendorId);
141+
return new LauncherResponse(LauncherResponse.STATUS_SUCCESS, "");
142+
}
143+
144+
@Override
145+
public LauncherResponse hideApp(Application app) {
146+
Log.i(TAG, "Hide app id:" + app.applicationId + " cid:" + app.catalogVendorId);
147+
return new LauncherResponse(LauncherResponse.STATUS_SUCCESS, "");
148+
}
149+
}

examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/AppPlatformService.java

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.util.Log;
2626
import androidx.annotation.NonNull;
2727
import com.matter.tv.app.api.SupportedCluster;
28+
import com.matter.tv.server.handlers.ApplicationLauncherManagerImpl;
2829
import com.matter.tv.server.handlers.ContentAppEndpointManagerImpl;
2930
import com.matter.tv.server.model.ContentApp;
3031
import com.matter.tv.server.receivers.ContentAppDiscoveryService;
@@ -194,6 +195,7 @@ public void addContentApp(ContentApp app) {
194195
}
195196
}
196197

198+
197199
private Collection<ContentAppSupportedCluster> mapSupportedClusters(
198200
Collection<SupportedCluster> supportedClusters) {
199201
return supportedClusters

0 commit comments

Comments
 (0)