Home | History | Annotate | Download | only in tuningfork
      1 /*
      2  * Copyright 2019 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 #pragma once
     18 
     19 #include <string>
     20 #include <jni.h>
     21 
     22 class AAsset;
     23 
     24 namespace tuningfork {
     25 
     26 namespace apk_utils {
     27 
     28     // Get an asset from this APK's asset directory.
     29     // Returns NULL if the asset could not be found.
     30     // Asset_close must be called once the asset is no longer needed.
     31     AAsset* GetAsset(JNIEnv* env, jobject activity, const char* name);
     32 
     33     // Get the app's version code. Also fills packageNameStr, if not null, with
     34     // the package name.
     35     int GetVersionCode(JNIEnv *env, jobject context, std::string* packageNameStr = nullptr);
     36 
     37 } // namespace apk_utils
     38 
     39 namespace file_utils {
     40 
     41     // Creates the directory if it does not exist. Returns true if the directory
     42     //  already existed or could be created.
     43     bool CheckAndCreateDir(const std::string& path);
     44 
     45     bool FileExists(const std::string& fname);
     46 
     47     // Call NativeActivity.getCacheDir via JNI
     48     std::string GetAppCacheDir(JNIEnv* env, jobject activity);
     49 
     50 } // namespace file_utils
     51 
     52 // Get a unique identifier using java.util.UUID
     53 std::string UniqueId(JNIEnv* env);
     54 
     55 } // namespace tuningfork
     56