1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package ohos.devtools.views.layout.utils; 17 18 import ohos.devtools.datasources.utils.session.service.SessionManager; 19 20 import java.io.File; 21 import java.util.Locale; 22 23 /** 24 * TraceStreamerUtils 25 * 26 * @since 2021/11/22 27 */ 28 public class TraceStreamerUtils { 29 private static TraceStreamerUtils traceStreamerUtils = new TraceStreamerUtils(); 30 private static final String DIR_STR = "trace_streamer" + File.separator; 31 private static final String LOG_STR = "trace_streamer" + File.separator + "trace_streamer.log"; 32 private static final String DB_NAME = "trace_streamer.db"; 33 private static final String WIN_APP = "trace_streamer.exe"; 34 private static final String MAC_APP = "trace_streamer"; 35 36 /** 37 * getInstance 38 * 39 * @return TraceStreamerUtils 40 */ getInstance()41 public static TraceStreamerUtils getInstance() { 42 return traceStreamerUtils; 43 } 44 45 /** 46 * getBaseDir 47 * 48 * @return String 49 */ getBaseDir()50 public String getBaseDir() { 51 String pluginPath = SessionManager.getInstance().getPluginPath(); 52 return pluginPath + DIR_STR; 53 } 54 55 /** 56 * getBaseDir 57 * 58 * @return String 59 */ getCreateFileDir()60 public String getCreateFileDir() { 61 String pluginPath = SessionManager.getInstance().tempPath(); 62 String path = pluginPath + DIR_STR; 63 File tmpPath = new File(path); 64 if (!tmpPath.exists()) { 65 tmpPath.mkdirs(); 66 } 67 return path; 68 } 69 70 /** 71 * getLogPath 72 * 73 * @param dbName dbName 74 * @return String 75 */ getLogPath(String dbName)76 public String getLogPath(String dbName) { 77 String tmpPath = SessionManager.getInstance().tempPath(); 78 return tmpPath + DIR_STR + dbName + ".ohos.ts"; 79 } 80 81 /** 82 * getDbPath 83 * 84 * @return String 85 */ getDbPath()86 public String getDbPath() { 87 return getCreateFileDir() + DB_NAME; 88 } 89 90 /** 91 * getDbPath 92 * 93 * @param dbName dbName 94 * @return String 95 */ getDbPath(String dbName)96 public String getDbPath(String dbName) { 97 return getCreateFileDir() + dbName; 98 } 99 100 /** 101 * getTraceStreamerApp 102 * 103 * @return String 104 */ getTraceStreamerApp()105 public String getTraceStreamerApp() { 106 String traceStreamerApp = WIN_APP; 107 if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("mac")) { 108 traceStreamerApp = MAC_APP; 109 } 110 return traceStreamerApp; 111 } 112 } 113