1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 package com.example.executorchllamademo;
10 
11 import android.app.Application;
12 import android.util.Log;
13 import java.util.ArrayList;
14 
15 public class ETLogging extends Application {
16   private static ETLogging singleton;
17 
18   private ArrayList<AppLog> logs;
19   private DemoSharedPreferences mDemoSharedPreferences;
20 
21   @Override
onCreate()22   public void onCreate() {
23     super.onCreate();
24     singleton = this;
25     mDemoSharedPreferences = new DemoSharedPreferences(this.getApplicationContext());
26     logs = mDemoSharedPreferences.getSavedLogs();
27     if (logs == null) { // We don't have existing sharedPreference stored
28       logs = new ArrayList<>();
29     }
30   }
31 
getInstance()32   public static ETLogging getInstance() {
33     return singleton;
34   }
35 
log(String message)36   public void log(String message) {
37     AppLog appLog = new AppLog(message);
38     logs.add(appLog);
39     Log.d("ETLogging", appLog.getMessage());
40   }
41 
getLogs()42   public ArrayList<AppLog> getLogs() {
43     return logs;
44   }
45 
clearLogs()46   public void clearLogs() {
47     logs.clear();
48     mDemoSharedPreferences.removeExistingLogs();
49   }
50 
saveLogs()51   public void saveLogs() {
52     mDemoSharedPreferences.saveLogs();
53   }
54 }
55