def initWord2Vec(appCategoryList, appCategoryListSelection, appDescriptionsFile): exampleLDAExecution() sys.exit(1) dbHandle = databaseHandler.dbConnectionCheck() #DB Open with open(appDescriptionsFile, 'w') as fp: if appCategoryListSelection == 'top': #get the descriptions for top apps json.dump(sad.getTopApps(dbHandle), fp, indent=4) elif appCategoryListSelection == 'all': #get the descriptions for all apps json.dump(sad.getAllApps(dbHandle), fp, indent=4) elif appCategoryListSelection == 'cattop': #get the descriptions for category wise top apps json.dump(sad.getCategoryAppsTopFewThousands(dbHandle), fp, indent=4) elif appCategoryListSelection == 'hmdtop': #get the descriptions for hmd top apps json.dump(sad.getHMDAppsTopFewThousands(dbHandle, appCategoryList), fp, indent=4) else: #get the descriptions for category list apps json.dump(sad.getCategoryApps(dbHandle, appCategoryList), fp, indent=4) dbHandle.close() #DB Close
def doTask(): currentId = "" dbHandle = databaseHandler.dbConnectionCheck() # DB Open # TEST CODE FOR ONE APP # extractPermissionsInfo(dbHandle,"a.a.a.A") # extractPermissionsInfo(dbHandle,"com.expedia.bookings") # extractPermissionsInfo(dbHandle,"com.ioob.openmovies") # sys.exit(0) # TEST CODE FOR ONE APP cursor = dbHandle.cursor() loopcount = findCountOfLoopsForURLsToBeParsed(cursor) for counter in range(0, loopcount): currentId = getGSFId(currentId) sqlStatement = "SELECT `id`, `app_pkg_name` FROM `appurls` WHERE `perm_extracted` = 0 LIMIT 150;" try: cursor.execute(sqlStatement) queryOutput = cursor.fetchall() except: print "Unexpected error:", sys.exc_info()[0] raise pkgNameList = [] print "loop: ", counter for row in queryOutput: pkgNameList.append(row[1]) extractPermissionsInfo(dbHandle, row[1], currentId) updatePermExtracted(dbHandle, row[0]) time.sleep( 1800 ) # Sleep for 30 minutes every GSF ID call for 150 app's permission extraction request
def insertInDB(app_pkg_name,paid): dbHandle = databaseHandler.dbConnectionCheck() # DB Open sqlStatement = "UPDATE `appdata` SET `paid`= "+str(paid)+" WHERE `app_pkg_name` = '"+app_pkg_name+"';" print sqlStatement logging.debug("Statement: "+sqlStatement) databaseHandler.dbManipulateData(dbHandle, sqlStatement) dbHandle.close() #DB Close
def doTask(baseURL): dbHandle = databaseHandler.dbConnectionCheck() # DB Open for appinfo in json.loads( open('Playdrone_Dataset_2014_10_31.json', 'r').read().decode('utf8')): app_pkg_name = appinfo["app_id"] app_url = baseURL + app_pkg_name playdrone_metadata_url = appinfo["metadata_url"] playdrone_apk_url = "" if 'apk_url' in appinfo: playdrone_apk_url = appinfo["apk_url"] updateURLs(dbHandle, app_pkg_name, app_url, playdrone_metadata_url, playdrone_apk_url) # print appinfo["title"], # print appinfo["developer_name"] # print appinfo["category"] # print appinfo["free"] # print appinfo["version_code"] # print appinfo["version_string"] # print appinfo["installation_size"] # print appinfo["downloads"] # print appinfo["star_rating"] # print appinfo["snapshot_date"] dbHandle.close() #DB Close
def getDBData(): appDict = {} dbHandle = db.dbConnectionCheck() cursor = dbHandle.cursor(buffered=True) sqlStatement = "select a.app_pkg_name, b.name from appdata a, permissions b, appperm c where a.id = c.app_id and b.id = c.perm_id and a.id in (select id from appdata order by installs desc, review_rating desc);" try: cursor.execute(sqlStatement) resultSet = cursor.fetchall() for row in resultSet: pkgName = str(row[0]) permission = str(row[1]) if pkgName in appDict: permissions = appDict[pkgName] permissions.append(permission) appDict[pkgName] = permissions else: permissions = [] permissions.append(permission) appDict[pkgName] = permissions except: print('Unexpected error: ' + str(sys.exc_info()[0])) cursor.close dbHandle.close() return appDict
def doTask(): dbHandle = databaseHandler.dbConnectionCheck() # DB Open #Created a view for this data, i.e. valid_app_playdrone_metadata_url_view using that now #sqlStatement = "SELECT a.`playdrone_metadata_url`, a.`app_pkg_name`, a.`id` FROM `appurls` a, `appdata` b WHERE `playdrone_metadata_url` IS NOT NULL AND a.`app_pkg_name` = b.`app_pkg_name` AND a.`perm_extracted` = 0;" sqlStatement = "SELECT * FROM `valid_app_playdrone_metadata_url_view`;" cursor = dbHandle.cursor() try: cursor.execute(sqlStatement) queryOutput = cursor.fetchall() except: print "Unexpected error:", sys.exc_info()[0] raise for row in queryOutput: # If we want to update the permissions that we have not extracted we must avoid doing the following as it will skip an app if even a single permission for it has been extracted before. # For the time being we are doing this so that we are not blocked by the servers. if isAPKPermissionsAlreadyInTable(dbHandle, row[1]) == True: print "Moving on to extracting permissions for the next app. This one is already in the database." else: readAppJSONForPermissionInfo(dbHandle, row[0], row[1]) updatePermExtracted( dbHandle, row[2] ) # Update the perm_extracted flag in the appurls table to ensure we don't repeatedly look for the same app info dbHandle.close() #DB Close
def doTask(): browser = "firefox" numberOfThreads = int(sys.argv[1]) #https://play.google.com/store/apps/details?id=com.syntellia.fleksy.kb #readInputFile(numberOfThreads, browser) dbHandle = databaseHandler.dbConnectionCheck() # DB Open cursor = dbHandle.cursor() countOfURLs = 0 numberOfSteps = 0 sqlStatement = "SELECT COUNT(`id`) FROM `appurls` WHERE `downloaded` = 0;" try: cursor.execute(sqlStatement) queryOutput = cursor.fetchall() except: print "Unexpected error:", sys.exc_info()[0] raise for row in queryOutput: countOfURLs = row[0] stepSize = 10#0000 numberOfSteps = 1#countOfURLs/stepSize for stepCount in range(0,numberOfSteps): rowCount = stepCount * stepSize offset = rowCount + 1 # sqlStatement = "SELECT `id`, `app_url` FROM `appurls` WHERE `downloaded` = 0 LIMIT "+str(offset)+","+str(stepSize)+";" sqlStatement = "SELECT `id`, `app_url` FROM `appurls` WHERE `downloaded` = 0 LIMIT "+str(50000)+","+str(stepSize)+";" try: cursor.execute(sqlStatement) queryOutput = cursor.fetchall() except: print "Unexpected error:", sys.exc_info()[0] raise extractPermissions(dbHandle,queryOutput,browser,numberOfThreads)
def initClustering(username, api_key, predictedClustersFile, appMatrixFile, appCategoryList, appCategoryListSelection, permissionRestrictionList, restrictionType): dbHandle = databaseHandler.dbConnectionCheck() #DB Open if appCategoryListSelection == 'top': #generate the permission matrix for top apps permissionsSet, permissionsDict = generateAppMatrixTopApps( dbHandle, permissionRestrictionList, restrictionType) elif appCategoryListSelection == 'all': #generate the permission matrix for all apps permissionsSet, permissionsDict = generateAppMatrixAllApps( dbHandle, permissionRestrictionList, restrictionType) elif appCategoryListSelection == 'cattop': #generate the permission matrix for category wise top apps permissionsSet, permissionsDict = generateAppMatrixCatTopApps( dbHandle, permissionRestrictionList, restrictionType) elif appCategoryListSelection == 'hmdtop': #generate the permission matrix for hmd top apps permissionsSet, permissionsDict = generateAppMatrixHMDTopApps( dbHandle, appCategoryList, permissionRestrictionList, restrictionType) else: #generate the permission matrix for category list apps permissionsSet, permissionsDict = generateAppMatrixCatApps( dbHandle, appCategoryList, permissionRestrictionList, restrictionType) runCl.runClustering(username, api_key, appCategoryListSelection, predictedClustersFile, permissionsSet, permissionsDict, appMatrixFile) dbHandle.close() #DB Close
def extractPermissionsInfo(dbHandle, pkgName, GSFId): if isAPKPermissionsAlreadyInTable(dbHandle, pkgName) == True: print "Moving on to extracting permissions for the next app. This one is already in the database." else: # Extract permissions using the API and store in the DB pkgNameList = [] pkgNameList.append(pkgName) # API call to unofficial Google Play API written in Python by egirault listOfPermissions = permissions.getPackagePermission( pkgNameList, GSFId) # print listOfPermissions for permissionName in listOfPermissions: dbHandle = databaseHandler.dbConnectionCheck() # See if the permission is in the table if not insert it and get its id sqlStatementPermName = "SELECT id FROM `permissions` WHERE `name` = '" + permissionName + "';" permissionId = getPermissionId(dbHandle, sqlStatementPermName, permissionName) # Find the App's Id in the DB # Assumption is that the crawlURL has already extracted all information about the app and the same is in the appdata table # If that is not true this step will fail and we will have to skip and go to the next app sqlStatementAppPkgName = "SELECT id FROM `appdata` WHERE `app_pkg_name` = '" + pkgName + "';" appId = getAppId(dbHandle, sqlStatementAppPkgName, pkgName) if appId > 0: # Insert the App_Id and corresponding Perm_Id in to the DB sqlStatement = "INSERT INTO `appperm`(`app_id`,`perm_id`) VALUES (" + str( appId) + "," + str(permissionId) + ");" print sqlStatement databaseHandler.dbManipulateData(dbHandle, sqlStatement) else: print "Moving on to the next app. This app has not been extracted from Google Play Store."
def downloadAPKFromPhone(): urlPrefix = "https://play.google.com/store/apps/details?id=" listOfPackages = subprocess.check_output( ["adb", "shell", "pm", "list", "packages"]) # This is a brilliant Python line I learnt from AK # lines = [line.strip() for line in listOfPackages.split()] for line in listOfPackages.split(): package = line.strip().split(":")[-1] urlPrefix = "https://play.google.com/store/apps/details?id=" urlExtract = urlPrefix + package if verifyPresentInAppMarket(urlExtract): dbHandle = databaseHandler.dbConnectionCheck() # DB Open sqlStatement = "INSERT INTO `appurls`(`app_pkg_name`,`app_url`,`downloaded`) VALUES('" + package + "', '" + urlExtract + "', 1);" try: databaseHandler.dbManipulateData(dbHandle, sqlStatement) except _mysql_exceptions.IntegrityError: print "package", package, "was present, updating now" sqlStatement = "SELECT `id` FROM `appurls` WHERE app_pkg_name = '" + package + "';" cursor = dbHandle.cursor() try: cursor.execute(sqlStatement) queryOutput = cursor.fetchall() except: print "Unexpected error:", sys.exc_info()[0] raise for row in queryOutput: updateDownloaded(dbHandle, row[0]) dbHandle.close() #DB Close # Get the path of the apk and extract it path = subprocess.check_output( ["adb", "shell", "pm", "path", package]).strip().split(":")[-1] # If the apps download directory doesn't exist just create it currentDirectory = os.getcwd() osInfo = platform.system() if osInfo == 'Windows': appsDownloadDirectory = currentDirectory + "\\apps\\" downloadAPK(appsDownloadDirectory, path) elif osInfo == 'Linux': appsDownloadDirectory = currentDirectory + "/apps/" downloadAPK(appsDownloadDirectory, path) else: sys.stderr.write( 'The current os not supported at the moment.\n') sys.exit(1) copiedFromPhoneAPKName = appsDownloadDirectory + path.split( "/")[-1] realPackageBasedAPKName = appsDownloadDirectory + package + ".apk" try: os.rename(copiedFromPhoneAPKName, realPackageBasedAPKName) except WindowsError: # The file already exists, we should copy the new apk over it os.remove(realPackageBasedAPKName) os.rename(copiedFromPhoneAPKName, realPackageBasedAPKName) os.chdir(currentDirectory)
def insertInDB(dbHandle, review_rating, app_pkg_name): dbHandle = databaseHandler.dbConnectionCheck() # DB Open # app_dict = json.loads(open('appRating.json','r').read()) # for app_pkg_name, review_rating in app_dict.iteritems(): sqlStatement = "UPDATE `appdata` SET `review_rating`= " + str( review_rating) + " WHERE `app_pkg_name` = '" + app_pkg_name + "';" print sqlStatement logging.debug("Statement: " + sqlStatement) databaseHandler.dbManipulateData(dbHandle, sqlStatement)
def main(argv): startTime = time.time() dbHandle = db.dbConnectionCheck() appList = getAppList() appDict = getAppPermData(dbHandle, appList) appDict = getAppCatData(dbHandle, appList, appDict) dbHandle.close() open("data.json", "w").write(json.dumps(appDict, indent=4)) executionTime = str((time.time() - startTime) / 60) print 'Execution time was: ' + executionTime + ' minutes'
def insertIntoDB(name, protectionLevel, permissionGroup="NULL", permissionFlags="NULL"): sqlStatement = "insert into permissions(name, protection_level, permission_group, permission_flags) values('" + name + "', '" + protectionLevel + "', '" + permissionGroup + "', '" + permissionFlags + "') on duplicate key update protection_level = '" + protectionLevel + "', permission_group = '" + permissionGroup + "', permission_flags = '" + permissionFlags + "';" if permissionFlags == '': sqlStatement = "insert into permissions(name, protection_level, permission_group, permission_flags) values('" + name + "', '" + protectionLevel + "', '" + permissionGroup + "', NULL) on duplicate key update protection_level = '" + protectionLevel + "', permission_group = '" + permissionGroup + "', permission_flags = NULL;" dbHandle = databaseHandler.dbConnectionCheck() databaseHandler.dbManipulateData(dbHandle, sqlStatement)
def getJaccardSimilarity(app1, app2): dbHandle = databaseHandler.dbConnectionCheck() appIdVectorSQLQueryList = "'" + app1 + "','" + app2 + "'" sqlStatement = "SELECT app.`app_pkg_name`, a.`perm_id` FROM `appperm` a, `appdata` app WHERE a.`app_id` = app.`id` AND app.`app_pkg_name` IN (" + appIdVectorSQLQueryList + ");" print sqlStatement permissionsSet, permissionsDict = generatePermVector( dbHandle, sqlStatement) print wjs.computeJaccardMatrix(permissionsSet, permissionsDict) result = (wjs.computeJaccardMatrix(permissionsSet, permissionsDict)[0])[0][1] return result
def writeCategoryJson(searchStringList): dbHandle = databaseHandler.dbConnectionCheck() #DB Open mainDict = {} for searchString in searchStringList: appDict = getData(searchString, dbHandle) # pp(appDict) for app in appDict: # print app mainDict[app] = appDict[app] json.dump(mainDict, open('category.json', 'w'), sort_keys=True, indent=4) dbHandle.close() #DB Close
def writeCategoryJson(jsonDict): dbHandle = databaseHandler.dbConnectionCheck() #DB Open copyDict = jsonDict for app in jsonDict: if jsonDict[app]["google_play_category"] == "": print "Trying to update data for: "+app category = getData(app,dbHandle) if category != "": copyDict[app]["google_play_category"] = category print "Updated data for: "+app json.dump(copyDict, open('newcategory.json', 'w'), sort_keys = True, indent = 4) dbHandle.close() #DB Close
def generatePermissionsRequestedByAppFrequencyHistogram(username, apiKey): dbHandle = databaseHandler.dbConnectionCheck() #DB Open # crawlUrl(dbHandle, "https://raw.githubusercontent.com/android/platform_frameworks_base/master/core/res/AndroidManifest.xml") # sys.exit(1) cursor = dbHandle.cursor() sqlStatement = "SELECT * FROM `perm_app_count_view` LIMIT 25;" try: cursor.execute(sqlStatement) if cursor.rowcount > 0: queryOutput = cursor.fetchall() appCount = [] permName = [] for row in queryOutput: appCount.append(row[0]) permName.append(row[1]) except: logging.debug('Unexpected error:' + sys.exc_info()[0]) raise dbHandle.close() #DB Close tls.set_credentials_file(username, apiKey) tracePerm = Bar(x=permName, y=appCount, name='App frequency count', marker=Marker(color='rgb(55, 83, 100)')) data = Data([tracePerm]) layout = Layout(title='Permission vs App frequency count', xaxis=XAxis(title='Permission', titlefont=Font(size=16, color='rgb(107, 107, 107)'), tickfont=Font(size=14, color='rgb(107, 107, 107)')), yaxis=YAxis(title='App frequency', titlefont=Font(size=16, color='rgb(107, 107, 107)'), tickfont=Font(size=14, color='rgb(107, 107, 107)')), legend=Legend(x=0, y=1.0, bgcolor='rgba(255, 255, 255, 0)', bordercolor='rgba(255, 255, 255, 0)'), barmode='group', bargap=0.15, bargroupgap=0.1) fig = Figure(data=data, layout=layout) plot_url = py.plot(fig, filename='perm-app') logging.debug('Check out the URL: ' + plot_url + ' for your plot')
def main(argv): if len(sys.argv) != 1: sys.stderr.write('Usage: python weightedJaccardSimilarity.py\n') sys.exit(1) dbHandle = databaseHandler.dbConnectionCheck() #DB Open startTime = time.time() #Compute Jaccard Similarity getAppCountRequestingPermissions(dbHandle) executionTime = str((time.time() - startTime) * 1000) print "Execution time was: " + executionTime + " ms" dbHandle.close() #DB Close
def writeCategoryJson(appList): dbHandle = databaseHandler.dbConnectionCheck() #DB Open mainDict = {} for app in appList: appDict = {} appDict["annotated_category"] = '' appDict["google_play_category"] = getData(app, dbHandle) mainDict[app] = appDict json.dump(mainDict, open('newcategory.json', 'w'), sort_keys=True, indent=4) dbHandle.close() #DB Close
def doTask(): dbHandle = databaseHandler.dbConnectionCheck() # DB Open cursor = dbHandle.cursor() sqlStatement = "SELECT `app_pkg_name` FROM `appdata`;" appUrlList = [] try: cursor.execute(sqlStatement) for app in cursor: appUrlList.append('https://play.google.com/store/apps/details?id='+app[0]) except: print 'Unexpected error in updatePaidOrFree:', sys.exc_info()[0] raise cursor.close() dbHandle.close() #DB Close for appUrl in appUrlList: getPaidOrFree(appUrl)
def doTask(): dbHandle = databaseHandler.dbConnectionCheck() # DB Open # If the apps download directory doesn't exist just create it currentDirectory = os.getcwd() osInfo = platform.system() if osInfo == 'Windows': sqlScriptPath = currentDirectory + "\\sqlScripts\\ddl.sql" elif osInfo == 'Linux': sqlScriptPath = currentDirectory + "/sqlScripts/ddl.sql" else: sys.stderr.write('The current os not supported at the moment.\n') sys.exit(1) runSQLFile(sqlScriptPath, dbHandle) dbHandle.close() #DB Close
def doTask(cmdLineArg): dbHandle = databaseHandler.dbConnectionCheck() # DB Open if cmdLineArg == "i": oneTimeCreateListOfAppsFromAlphabeticalSearch( dbHandle) # First level of search for app urls elif cmdLineArg == "m": getURLsForExtractingMoreURLs( dbHandle) # Second level of search for app urls elif cmdLineArg == "a": getURLsForParsingAppData(dbHandle) # Extract app data elif cmdLineArg == "s": getDataForAppList( dbHandle ) # Extract a curated list of apps from the Google Play Store. Get urls, get related and get app data else: sys.stderr.write('Usage: python crawlURLs.py [i|m|a|s]\n') dbHandle.close() #DB Close
def evaluateCluster(clusterInfo,groundTruth=None): dbHandle = databaseHandler.dbConnectionCheck() #DB Open labels_pred = [] labels_true = [] appNames = [] keylistPred = clusterInfo.keys() keylistPred.sort() for key in keylistPred: labels_pred.append(clusterInfo[key]) appNames.append(key) if groundTruth == None: labels_true = getCategoryNumbers(appNames,dbHandle) else: keylistTrue = groundTruth.keys() keylistTrue.sort() for key in keylistTrue: labels_true.append(groundTruth[key]) # print "labels_pred = ",labels_pred # print "labels_true = ",labels_true logging.debug('Right before cluster evaluation') clusterEvaluationResults = {} clusterEvaluationResults["adjusted_rand_score"] = str(metrics.adjusted_rand_score(labels_true, labels_pred)) logging.debug('Right before cluster evaluation1') clusterEvaluationResults["adjusted_mutual_info_score"] = str(metrics.adjusted_mutual_info_score(labels_true, labels_pred)) logging.debug('Right before cluster evaluation2') clusterEvaluationResults["homogeneity_score"] = str(metrics.homogeneity_score(labels_true, labels_pred)) logging.debug('Right before cluster evaluation3') clusterEvaluationResults["completeness_score"] = str(metrics.completeness_score(labels_true, labels_pred)) logging.debug('Right before cluster evaluation4') clusterEvaluationResults["v_measure_score"] = str(metrics.v_measure_score(labels_true, labels_pred)) logging.debug('Right before cluster evaluation5') clusterEvaluationResults["normalized_mutual_info_score"] = str(metrics.normalized_mutual_info_score(labels_true, labels_pred)) logging.debug('Right before cluster evaluation6') showClusterEvaluationResults(clusterEvaluationResults) dbHandle.close() #DB Close return clusterEvaluationResults
def storeDataonServer(url, searchStringList): dbHandle = databaseHandler.dbConnectionCheck() #DB Open # jsonString = '''{"applist": # [ # {"ABC":{"packageName":"ABC","appName":"ABC","versionInfo":"ABC"}}, # {"com.facebook.katana":{"packageName":"com.facebook.katana","appName":"Facebook","versionInfo":"1.0"}}, # {"com.facebook.orca":{"packageName":"com.facebook.orca","appName":"Messenger","versionInfo":"1.0"}} # ] # }''' jsonString = {} applist = [] for searchString in searchStringList: applist = getData(searchString, applist, dbHandle) jsonString['applist'] = applist json.dump(jsonString, open('search.json', 'w'), sort_keys=True, indent=4) serverResponse = requests.post(url, json.dumps(jsonString)) print serverResponse dbHandle.close() #DB Close
def doTask(inpath,benignMal): dbHandle = db.dbConnectionCheck() jsonFile=os.getcwd()+"/"+benignMal+'.json' if makeSurePathExists(inpath): os.chdir(inpath) count=0 bigAppDict = {} for apkFile in os.listdir(os.getcwd()): appDict={} if apkFile.endswith(".apk"): abspath=os.getcwd()+"/"+apkFile packageData="aapt dump badging "+abspath packageOutput=runShellCmdGetOutput(packageData) features=[] permissions=[] for appLine in packageOutput.split("\n"): if "package" in appLine: pkgInfo=appLine.split("'") try: appDict["pkgName"]=pkgInfo[1] appDict["verCode"]=pkgInfo[3] appDict["verName"]=pkgInfo[5] appDict["platformVer"]=pkgInfo[7] except IndexError: print 'skipping index' elif "uses-feature" in appLine: features.append(appLine.split("'")[1]) elif "uses-permission" in appLine: permissions.append(appLine.split("'")[1]) appDict["features"]=features appDict["permissions"]=permissions uploadPermInfoToDB(dbHandle,pkgInfo[1],permissions) appDict["benignMal"]=benignMal if "pkgName" in appDict: bigAppDict[appDict["pkgName"]]=appDict count+=1 if(count%100 == 0): print str(count), " apps done" open(jsonFile,'w').write(json.dumps(bigAppDict,indent=4)) dbHandle.close()
def doTask(): dbHandle = databaseHandler.dbConnectionCheck() # DB Open cursor = dbHandle.cursor() sqlStatement = "SELECT `app_pkg_name` FROM `appdata`;" appUrlList = [] appRatingJson = json.loads(open('appRating.json', 'r').read()) count = 0 try: cursor.execute(sqlStatement) for app in cursor: count += 1 if app[0] not in appRatingJson: appUrlList.append( 'https://play.google.com/store/apps/details?id=' + app[0]) except: print 'Unexpected error in updateReviewRatings:', sys.exc_info()[0] raise print len(appUrlList), count cursor.close() # open('appRating.json','w').write(json.dumps({},indent=4,sort_keys=True)) getReviewRatings(dbHandle, appUrlList) dbHandle.close() #DB Close
def evaluateCluster(clusterInfo): dbHandle = databaseHandler.dbConnectionCheck() #DB Open labels_pred = [] appNames = [] keylist = clusterInfo.keys() keylist.sort() for key in keylist: labels_pred.append(clusterInfo[key]) appNames.append(key) labels_true = getCategoryNumbers(appNames,dbHandle) clusterEvaluationResults = {} clusterEvaluationResults["adjusted_rand_score"] = str(metrics.adjusted_rand_score(labels_true, labels_pred)) clusterEvaluationResults["adjusted_mutual_info_score"] = str(metrics.adjusted_mutual_info_score(labels_true, labels_pred)) clusterEvaluationResults["homogeneity_score"] = str(metrics.homogeneity_score(labels_true, labels_pred)) clusterEvaluationResults["completeness_score"] = str(metrics.completeness_score(labels_true, labels_pred)) clusterEvaluationResults["v_measure_score"] = str(metrics.v_measure_score(labels_true, labels_pred)) dbHandle.close() #DB Close return clusterEvaluationResults
def extractAppPermData(): dbHandle = databaseHandler.dbConnectionCheck() #DB Open cursor = dbHandle.cursor() sqlStatement = "SELECT * FROM `app_perm_count_view`;" try: cursor.execute(sqlStatement) if cursor.rowcount > 0: queryOutput = cursor.fetchall() permCountDict = {} for row in queryOutput: permissionCount = row[1] if permCountDict.has_key(permissionCount): currentValue = permCountDict[permissionCount] permCountDict[permissionCount] = currentValue + 1 else: permCountDict[permissionCount] = 1 except: logging.debug('Unexpected error:' + sys.exc_info()[0]) raise dbHandle.close() #DB Close return permCountDict
def generateDataset(appMatrixFile, appCategoryList, appCategoryListSelection, permissionRestrictionList, restrictionType): dbHandle = databaseHandler.dbConnectionCheck() #DB Open if appCategoryListSelection == 'top': #generate the permission matrix for top apps appDict, permissionList = generateAppMatrixTopApps( dbHandle, permissionRestrictionList, restrictionType) elif appCategoryListSelection == 'all': #generate the permission matrix for all apps appDict, permissionList = generateAppMatrixAllApps( dbHandle, permissionRestrictionList, restrictionType) elif appCategoryListSelection == 'cattop': #generate the permission matrix for category wise top apps appDict, permissionList = generateAppMatrixCatTopApps( dbHandle, permissionRestrictionList, restrictionType) elif appCategoryListSelection == 'number': #generate the permission matrix for a number of apps appDict, permissionList = generateAppMatrixNumberApps( dbHandle, appCategoryList, permissionRestrictionList, restrictionType) elif appCategoryListSelection == 'hmdtop': #generate the permission matrix for hmd top apps appDict, permissionList = generateAppMatrixHMDTopApps( dbHandle, appCategoryList, permissionRestrictionList, restrictionType) else: #generate the permission matrix for category list apps appDict, permissionList = generateAppMatrixCatApps( dbHandle, appCategoryList, permissionRestrictionList, restrictionType) writeAppDictJson(appMatrixFile, appDict) writeArffFile(appMatrixFile, generateArffFileData(appDict, permissionList)) dbHandle.close() #DB Close
def preProcess(appCategoryListSelection, permissionRestrictionListSelection): dbHandle = databaseHandler.dbConnectionCheck() #DB Open sqlStatement = "SELECT * FROM `perm_app_count_view` LIMIT 0," appCategoryList = [] if appCategoryListSelection == 'med': appCategoryList = [ 'https://play.google.com/store/apps/category/MEDICAL' ] elif appCategoryListSelection == 'hea': appCategoryList = [ 'https://play.google.com/store/apps/category/HEALTH_AND_FITNESS' ] elif appCategoryListSelection == 'hmd': appCategoryList = [ 'https://play.google.com/store/apps/category/HEALTH_AND_FITNESS', 'https://play.google.com/store/apps/category/MEDICAL' ] elif appCategoryListSelection == 'hmdtop': appCategoryList = [ 'https://play.google.com/store/apps/category/HEALTH_AND_FITNESS', 'https://play.google.com/store/apps/category/MEDICAL' ] elif appCategoryListSelection == 'fabra': appCategoryList = [ 'https://play.google.com/store/apps/category/FAMILY_BRAINGAMES' ] elif appCategoryListSelection == 'top': appCategoryList = ['top'] elif appCategoryListSelection == 'all': appCategoryList = ['all'] elif appCategoryListSelection == 'cattop': appCategoryList = ['cattop'] else: appCategoryList.append(appCategoryListSelection) appCategoryListSelection = 'number' ''' This is the full list:- appCategoryList = ['https://play.google.com/store/apps/category/APP_WALLPAPER','https://play.google.com/store/apps/category/APP_WIDGETS','https://play.google.com/store/apps/category/BOOKS_AND_REFERENCE','https://play.google.com/store/apps/category/BUSINESS','https://play.google.com/store/apps/category/COMICS','https://play.google.com/store/apps/category/COMMUNICATION','https://play.google.com/store/apps/category/EDUCATION','https://play.google.com/store/apps/category/ENTERTAINMENT','https://play.google.com/store/apps/category/FAMILY','https://play.google.com/store/apps/category/FAMILY?age=AGE_RANGE1','https://play.google.com/store/apps/category/FAMILY?age=AGE_RANGE2','https://play.google.com/store/apps/category/FAMILY?age=AGE_RANGE3','https://play.google.com/store/apps/category/FAMILY_ACTION','https://play.google.com/store/apps/category/FAMILY_BRAINGAMES','https://play.google.com/store/apps/category/FAMILY_CREATE','https://play.google.com/store/apps/category/FAMILY_EDUCATION','https://play.google.com/store/apps/category/FAMILY_MUSICVIDEO','https://play.google.com/store/apps/category/FAMILY_PRETEND','https://play.google.com/store/apps/category/FINANCE','https://play.google.com/store/apps/category/GAME','https://play.google.com/store/apps/category/GAME_ACTION','https://play.google.com/store/apps/category/GAME_ADVENTURE','https://play.google.com/store/apps/category/GAME_ARCADE','https://play.google.com/store/apps/category/GAME_BOARD','https://play.google.com/store/apps/category/GAME_CARD','https://play.google.com/store/apps/category/GAME_CASINO','https://play.google.com/store/apps/category/GAME_CASUAL','https://play.google.com/store/apps/category/GAME_EDUCATIONAL','https://play.google.com/store/apps/category/GAME_MUSIC','https://play.google.com/store/apps/category/GAME_PUZZLE','https://play.google.com/store/apps/category/GAME_RACING','https://play.google.com/store/apps/category/GAME_ROLE_PLAYING','https://play.google.com/store/apps/category/GAME_SIMULATION','https://play.google.com/store/apps/category/GAME_SPORTS','https://play.google.com/store/apps/category/GAME_STRATEGY','https://play.google.com/store/apps/category/GAME_TRIVIA','https://play.google.com/store/apps/category/GAME_WORD','https://play.google.com/store/apps/category/HEALTH_AND_FITNESS','https://play.google.com/store/apps/category/LIBRARIES_AND_DEMO','https://play.google.com/store/apps/category/LIFESTYLE','https://play.google.com/store/apps/category/MEDIA_AND_VIDEO','https://play.google.com/store/apps/category/MEDICAL','https://play.google.com/store/apps/category/MUSIC_AND_AUDIO','https://play.google.com/store/apps/category/NEWS_AND_MAGAZINES','https://play.google.com/store/apps/category/PERSONALIZATION','https://play.google.com/store/apps/category/PHOTOGRAPHY','https://play.google.com/store/apps/category/PRODUCTIVITY','https://play.google.com/store/apps/category/SHOPPING','https://play.google.com/store/apps/category/SOCIAL','https://play.google.com/store/apps/category/SPORTS','https://play.google.com/store/apps/category/TOOLS','https://play.google.com/store/apps/category/TRANSPORTATION','https://play.google.com/store/apps/category/TRAVEL_AND_LOCAL','https://play.google.com/store/apps/category/WEATHER'] ''' permissionRestrictionList = [] if permissionRestrictionListSelection == 'top25': sqlStatement += "25;" #permissionRestrictionList = ['android.permission.INTERNET','android.permission.ACCESS_COARSE_LOCATION','android.permission.ACCESS_FINE_LOCATION','android.permission.ACCESS_LOCATION_EXTRA_COMMANDS','android.permission.ACCESS_NETWORK_STATE','android.permission.ACCESS_WIFI_STATE','android.permission.CALL_PHONE','android.permission.CAMERA','android.permission.GET_ACCOUNTS','android.permission.GET_TASKS','android.permission.MODIFY_AUDIO_SETTINGS','android.permission.READ_CALL_LOG','android.permission.READ_CONTACTS','android.permission.READ_EXTERNAL_STORAGE','android.permission.READ_PHONE_STATE','android.permission.RECEIVE_BOOT_COMPLETED','android.permission.RECORD_AUDIO','android.permission.SEND_SMS','android.permission.VIBRATE','android.permission.WAKE_LOCK','android.permission.WRITE_EXTERNAL_STORAGE','com.android.vending.BILLING','com.android.vending.CHECK_LICENSE','com.google.android.c2dm.permission.RECEIVE','com.google.android.providers.gsf.permission.READ_GSERVICE'] elif permissionRestrictionListSelection == 'top50': sqlStatement += "50;" elif permissionRestrictionListSelection == 'top75': sqlStatement += "75;" elif permissionRestrictionListSelection == 'top100': sqlStatement += "100;" elif permissionRestrictionListSelection == 'top125': sqlStatement += "125;" elif permissionRestrictionListSelection == 'top150': sqlStatement += "150;" elif permissionRestrictionListSelection == 'top175': sqlStatement += "175;" elif permissionRestrictionListSelection == 'top200': sqlStatement += "200;" elif permissionRestrictionListSelection == 'top225': sqlStatement += "225;" elif permissionRestrictionListSelection == 'top250': sqlStatement += "250;" elif permissionRestrictionListSelection == 'top275': sqlStatement += "275;" elif permissionRestrictionListSelection == 'top300': sqlStatement += "300;" elif permissionRestrictionListSelection == 'top500': sqlStatement += "500;" elif permissionRestrictionListSelection == 'top1000': sqlStatement += "1000;" elif permissionRestrictionListSelection == 'top10000': sqlStatement += "10000;" elif permissionRestrictionListSelection == 'top100000': sqlStatement += "100000;" elif permissionRestrictionListSelection == 'top200000': sqlStatement += "200000;" elif permissionRestrictionListSelection == 'all': sqlStatement = "ignore" permissionRestrictionList = [''] elif permissionRestrictionListSelection == 'google': sqlStatement = "ignore" permissionRestrictionList = [ 'android.permission.SEND_SMS', 'android.permission.SEND_RESPOND_VIA_MESSAGE', 'android.permission.RECEIVE_SMS', 'android.permission.RECEIVE_MMS', 'android.permission.CARRIER_FILTER_SMS', 'android.permission.RECEIVE_EMERGENCY_BROADCAST', 'android.permission.READ_CELL_BROADCASTS', 'android.permission.READ_SMS', 'android.permission.WRITE_SMS', 'android.permission.RECEIVE_WAP_PUSH', 'android.permission.RECEIVE_BLUETOOTH_MAP', 'android.permission.READ_CONTACTS', 'android.permission.WRITE_CONTACTS', 'android.permission.BIND_DIRECTORY_SEARCH', 'android.permission.READ_CALL_LOG', 'android.permission.WRITE_CALL_LOG', 'android.permission.READ_SOCIAL_STREAM', 'android.permission.WRITE_SOCIAL_STREAM', 'android.permission.READ_PROFILE', 'android.permission.WRITE_PROFILE', 'android.permission.BODY_SENSORS', 'android.permission.READ_CALENDAR', 'android.permission.WRITE_CALENDAR', 'android.permission.READ_USER_DICTIONARY', 'android.permission.WRITE_USER_DICTIONARY', 'com.android.browser.permission.READ_HISTORY_BOOKMARKS', 'com.android.browser.permission.WRITE_HISTORY_BOOKMARKS', 'com.android.alarm.permission.SET_ALARM', 'com.android.voicemail.permission.ADD_VOICEMAIL', 'com.android.voicemail.permission.WRITE_VOICEMAIL', 'com.android.voicemail.permission.READ_VOICEMAIL', 'android.permission.ACCESS_FINE_LOCATION', 'android.permission.ACCESS_COARSE_LOCATION', 'android.permission.ACCESS_MOCK_LOCATION', 'android.permission.ACCESS_LOCATION_EXTRA_COMMANDS', 'android.permission.INSTALL_LOCATION_PROVIDER', 'android.permission.HDMI_CEC', 'android.permission.LOCATION_HARDWARE', 'android.permission.INTERNET', 'android.permission.ACCESS_NETWORK_STATE', 'android.permission.ACCESS_WIFI_STATE', 'android.permission.CHANGE_WIFI_STATE', 'android.permission.READ_WIFI_CREDENTIAL', 'android.permission.ACCESS_WIMAX_STATE', 'android.permission.CHANGE_WIMAX_STATE', 'android.permission.SCORE_NETWORKS', 'android.permission.BLUETOOTH', 'android.permission.BLUETOOTH_ADMIN', 'android.permission.BLUETOOTH_PRIVILEGED', 'android.permission.BLUETOOTH_MAP', 'android.permission.BLUETOOTH_STACK', 'android.permission.NFC', 'android.permission.CONNECTIVITY_INTERNAL', 'android.permission.RECEIVE_DATA_ACTIVITY_CHANGE', 'android.permission.LOOP_RADIO', 'android.permission.NFC_HANDOVER_STATUS', 'android.permission.GET_ACCOUNTS', 'android.permission.AUTHENTICATE_ACCOUNTS', 'android.permission.USE_CREDENTIALS', 'android.permission.MANAGE_ACCOUNTS', 'android.permission.ACCOUNT_MANAGER', 'android.permission.CHANGE_WIFI_MULTICAST_STATE', 'android.permission.VIBRATE', 'android.permission.FLASHLIGHT', 'android.permission.WAKE_LOCK', 'android.permission.TRANSMIT_IR', 'android.permission.MODIFY_AUDIO_SETTINGS', 'android.permission.MANAGE_USB', 'android.permission.ACCESS_MTP', 'android.permission.HARDWARE_TEST', 'android.permission.ACCESS_FM_RADIO', 'android.permission.NET_ADMIN', 'android.permission.REMOTE_AUDIO_PLAYBACK', 'android.permission.TV_INPUT_HARDWARE', 'android.permission.CAPTURE_TV_INPUT', 'android.permission.OEM_UNLOCK_STATE', 'android.permission.ACCESS_PDB_STATE', 'android.permission.RECORD_AUDIO', 'android.permission.CAMERA', 'android.permission.CAMERA_DISABLE_TRANSMIT_LED', 'android.permission.PROCESS_OUTGOING_CALLS', 'android.permission.MODIFY_PHONE_STATE', 'android.permission.READ_PHONE_STATE', 'android.permission.READ_PRECISE_PHONE_STATE', 'android.permission.READ_PRIVILEGED_PHONE_STATE', 'android.permission.CALL_PHONE', 'android.permission.USE_SIP', 'android.permission.REGISTER_SIM_SUBSCRIPTION', 'android.permission.REGISTER_CALL_PROVIDER', 'android.permission.REGISTER_CONNECTION_MANAGER', 'android.permission.BIND_INCALL_SERVICE', 'android.permission.BIND_CONNECTION_SERVICE', 'android.permission.CONTROL_INCALL_EXPERIENCE', 'android.permission.READ_EXTERNAL_STORAGE', 'android.permission.WRITE_EXTERNAL_STORAGE', 'android.permission.WRITE_MEDIA_STORAGE', 'android.permission.MANAGE_DOCUMENTS', 'android.permission.DISABLE_KEYGUARD', 'android.permission.GET_TASKS', 'android.permission.REAL_GET_TASKS', 'android.permission.START_TASKS_FROM_RECENTS', 'android.permission.INTERACT_ACROSS_USERS', 'android.permission.INTERACT_ACROSS_USERS_FULL', 'android.permission.MANAGE_USERS', 'android.permission.GET_DETAILED_TASKS', 'android.permission.REORDER_TASKS', 'android.permission.REMOVE_TASKS', 'android.permission.MANAGE_ACTIVITY_STACKS', 'android.permission.START_ANY_ACTIVITY', 'android.permission.RESTART_PACKAGES', 'android.permission.KILL_BACKGROUND_PROCESSES', 'android.permission.SYSTEM_ALERT_WINDOW', 'android.permission.SET_WALLPAPER', 'android.permission.SET_WALLPAPER_HINTS', 'android.permission.SET_TIME', 'android.permission.SET_TIME_ZONE', 'android.permission.EXPAND_STATUS_BAR', 'android.permission.READ_SYNC_SETTINGS', 'android.permission.WRITE_SYNC_SETTINGS', 'android.permission.READ_SYNC_STATS', 'android.permission.SET_SCREEN_COMPATIBILITY', 'android.permission.ACCESS_ALL_EXTERNAL_STORAGE', 'android.permission.CHANGE_CONFIGURATION', 'android.permission.WRITE_SETTINGS', 'android.permission.WRITE_GSERVICES', 'android.permission.FORCE_STOP_PACKAGES', 'android.permission.RETRIEVE_WINDOW_CONTENT', 'android.permission.SET_ANIMATION_SCALE', 'android.permission.PERSISTENT_ACTIVITY', 'android.permission.GET_PACKAGE_SIZE', 'android.permission.SET_PREFERRED_APPLICATIONS', 'android.permission.RECEIVE_BOOT_COMPLETED', 'android.permission.BROADCAST_STICKY', 'android.permission.MOUNT_UNMOUNT_FILESYSTEMS', 'android.permission.MOUNT_FORMAT_FILESYSTEMS', 'android.permission.ASEC_ACCESS', 'android.permission.ASEC_CREATE', 'android.permission.ASEC_DESTROY', 'android.permission.ASEC_MOUNT_UNMOUNT', 'android.permission.ASEC_RENAME', 'android.permission.WRITE_APN_SETTINGS', 'android.permission.SUBSCRIBED_FEEDS_READ', 'android.permission.SUBSCRIBED_FEEDS_WRITE', 'android.permission.CHANGE_NETWORK_STATE', 'android.permission.CLEAR_APP_CACHE', 'android.permission.ALLOW_ANY_CODEC_FOR_PLAYBACK', 'android.permission.MANAGE_CA_CERTIFICATES', 'android.permission.RECOVERY', 'android.permission.BIND_JOB_SERVICE', 'android.permission.WRITE_SECURE_SETTINGS', 'android.permission.DUMP', 'android.permission.READ_LOGS', 'android.permission.SET_DEBUG_APP', 'android.permission.SET_PROCESS_LIMIT', 'android.permission.SET_ALWAYS_FINISH', 'android.permission.SIGNAL_PERSISTENT_PROCESSES', 'android.permission.DIAGNOSTIC', 'android.permission.STATUS_BAR', 'android.permission.STATUS_BAR_SERVICE', 'android.permission.FORCE_BACK', 'android.permission.UPDATE_DEVICE_STATS', 'android.permission.GET_APP_OPS_STATS', 'android.permission.UPDATE_APP_OPS_STATS', 'android.permission.INTERNAL_SYSTEM_WINDOW', 'android.permission.MANAGE_APP_TOKENS', 'android.permission.FREEZE_SCREEN', 'android.permission.INJECT_EVENTS', 'android.permission.FILTER_EVENTS', 'android.permission.RETRIEVE_WINDOW_TOKEN', 'android.permission.FRAME_STATS', 'android.permission.TEMPORARY_ENABLE_ACCESSIBILITY', 'android.permission.SET_ACTIVITY_WATCHER', 'android.permission.SHUTDOWN', 'android.permission.STOP_APP_SWITCHES', 'android.permission.GET_TOP_ACTIVITY_INFO', 'android.permission.READ_INPUT_STATE', 'android.permission.BIND_INPUT_METHOD', 'android.permission.BIND_ACCESSIBILITY_SERVICE', 'android.permission.BIND_PRINT_SERVICE', 'android.permission.BIND_NFC_SERVICE', 'android.permission.BIND_PRINT_SPOOLER_SERVICE', 'android.permission.BIND_TEXT_SERVICE', 'android.permission.BIND_VPN_SERVICE', 'android.permission.BIND_WALLPAPER', 'android.permission.BIND_VOICE_INTERACTION', 'android.permission.MANAGE_VOICE_KEYPHRASES', 'android.permission.BIND_REMOTE_DISPLAY', 'android.permission.BIND_TV_INPUT', 'android.permission.MODIFY_PARENTAL_CONTROLS', 'android.permission.BIND_DEVICE_ADMIN', 'android.permission.MANAGE_DEVICE_ADMINS', 'android.permission.SET_ORIENTATION', 'android.permission.SET_POINTER_SPEED', 'android.permission.SET_INPUT_CALIBRATION', 'android.permission.SET_KEYBOARD_LAYOUT', 'android.permission.INSTALL_PACKAGES', 'android.permission.CLEAR_APP_USER_DATA', 'android.permission.DELETE_CACHE_FILES', 'android.permission.DELETE_PACKAGES', 'android.permission.MOVE_PACKAGE', 'android.permission.CHANGE_COMPONENT_ENABLED_STATE', 'android.permission.GRANT_REVOKE_PERMISSIONS', 'android.permission.ACCESS_SURFACE_FLINGER', 'android.permission.READ_FRAME_BUFFER', 'android.permission.ACCESS_INPUT_FLINGER', 'android.permission.CONFIGURE_WIFI_DISPLAY', 'android.permission.CONTROL_WIFI_DISPLAY', 'android.permission.CONTROL_VPN', 'android.permission.CAPTURE_AUDIO_OUTPUT', 'android.permission.CAPTURE_AUDIO_HOTWORD', 'android.permission.MODIFY_AUDIO_ROUTING', 'android.permission.CAPTURE_VIDEO_OUTPUT', 'android.permission.CAPTURE_SECURE_VIDEO_OUTPUT', 'android.permission.MEDIA_CONTENT_CONTROL', 'android.permission.BRICK', 'android.permission.REBOOT', 'android.permission.DEVICE_POWER', 'android.permission.USER_ACTIVITY', 'android.permission.NET_TUNNELING', 'android.permission.FACTORY_TEST', 'android.permission.BROADCAST_PACKAGE_REMOVED', 'android.permission.BROADCAST_SMS', 'android.permission.BROADCAST_WAP_PUSH', 'android.permission.BROADCAST_NETWORK_PRIVILEGED', 'android.permission.MASTER_CLEAR', 'android.permission.CALL_PRIVILEGED', 'android.permission.PERFORM_CDMA_PROVISIONING', 'android.permission.CONTROL_LOCATION_UPDATES', 'android.permission.ACCESS_CHECKIN_PROPERTIES', 'android.permission.PACKAGE_USAGE_STATS', 'android.permission.BATTERY_STATS', 'android.permission.BACKUP', 'android.permission.CONFIRM_FULL_BACKUP', 'android.permission.BIND_REMOTEVIEWS', 'android.permission.BIND_APPWIDGET', 'android.permission.BIND_KEYGUARD_APPWIDGET', 'android.permission.MODIFY_APPWIDGET_BIND_PERMISSIONS', 'android.permission.CHANGE_BACKGROUND_DATA_SETTING', 'android.permission.GLOBAL_SEARCH', 'android.permission.GLOBAL_SEARCH_CONTROL', 'android.permission.READ_SEARCH_INDEXABLES', 'android.permission.SET_WALLPAPER_COMPONENT', 'android.permission.READ_DREAM_STATE', 'android.permission.WRITE_DREAM_STATE', 'android.permission.ACCESS_CACHE_FILESYSTEM', 'android.permission.COPY_PROTECTED_DATA', 'android.permission.CRYPT_KEEPER', 'android.permission.READ_NETWORK_USAGE_HISTORY', 'android.permission.MANAGE_NETWORK_POLICY', 'android.permission.MODIFY_NETWORK_ACCOUNTING', 'android.intent.category.MASTER_CLEAR.permission.C2D_MESSAGE', 'android.permission.PACKAGE_VERIFICATION_AGENT', 'android.permission.BIND_PACKAGE_VERIFIER', 'android.permission.SERIAL_PORT', 'android.permission.ACCESS_CONTENT_PROVIDERS_EXTERNALLY', 'android.permission.UPDATE_LOCK', 'android.permission.ACCESS_NOTIFICATIONS', 'android.permission.ACCESS_KEYGUARD_SECURE_STORAGE', 'android.permission.CONTROL_KEYGUARD', 'android.permission.TRUST_LISTENER', 'android.permission.PROVIDE_TRUST_AGENT', 'android.permission.LAUNCH_TRUST_AGENT_SETTINGS', 'android.permission.BIND_TRUST_AGENT', 'android.permission.BIND_NOTIFICATION_LISTENER_SERVICE', 'android.permission.BIND_CONDITION_PROVIDER_SERVICE', 'android.permission.BIND_DREAM_SERVICE', 'android.permission.INVOKE_CARRIER_SETUP', 'android.permission.ACCESS_NETWORK_CONDITIONS', 'android.permission.ACCESS_DRM_CERTIFICATES', 'android.permission.MANAGE_MEDIA_PROJECTION', 'android.permission.READ_INSTALL_SESSIONS', 'android.permission.REMOVE_DRM_CERTIFICATES', 'android.permission.BIND_CARRIER_MESSAGING_SERVICE' ] else: #Select no permission restriction as we did not choose any restriction list permissionRestrictionList = [''] cursor = dbHandle.cursor() tempPermissionList = [] if sqlStatement != "ignore": try: cursor.execute(sqlStatement) logging.debug('Extracting permission list') if cursor.rowcount > 0: queryOutput = cursor.fetchall() for row in queryOutput: tempPermissionList.append(row[1]) except: logging.debug('Unexpected error in preProcess: ' + str(sys.exc_info()[0])) sys.exit(1) permissionRestrictionList = tempPermissionList ticks = time.time() uniformString = str(ticks).replace(".", "_") appMatrixFile = pd.getPath() + "appMatrix" + uniformString + ".arff" text_file = open(appMatrixFile, "w") text_file.write("") text_file.close() dbHandle.close() #DB Close return appMatrixFile, appCategoryList, appCategoryListSelection, permissionRestrictionList